From e45fbf91ce0e5c199599b7c54bead3fec45ad9ac Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 8 Mar 2022 23:53:52 +0000 Subject: [PATCH] [Network] Add a socket thread check and early exit for corner cases. --- netwerk/protocol/http/nsHttpConnectionMgr.cpp | 12 +++++++++++- netwerk/protocol/http/nsHttpConnectionMgr.h | 12 +++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index d402b41044..0243b55cd3 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -2638,6 +2638,7 @@ nsHttpConnectionMgr::OnMsgCompleteUpgrade(int32_t, ARefBase *param) void nsHttpConnectionMgr::OnMsgUpdateParam(int32_t inParam, ARefBase *) { + MOZ_ASSERT(OnSocketThread(), "not on socket thread"); uint32_t param = static_cast(inParam); uint16_t name = ((param) & 0xFFFF0000) >> 16; uint16_t value = param & 0x0000FFFF; @@ -2709,9 +2710,18 @@ nsHttpConnectionMgr::ActivateTimeoutTick() NS_WARNING("failed to create timer for http timeout management"); return; } + ReentrantMonitorAutoEnter mon(mReentrantMonitor); + if (!mSocketThreadTarget) { + NS_WARNING("HTTP Connection Manager: Cannot activate timout if not initialized or shutdown"); + return; + } mTimeoutTick->SetTarget(mSocketThreadTarget); } - + if (mIsShuttingDown) { // Atomic + // don't set a timer to generate an event if we're shutting down + // (mSocketThreadTarget might be null or garbage anyway if we're shutting down) + return; + } MOZ_ASSERT(!mTimeoutTickArmed, "timer tick armed"); mTimeoutTickArmed = true; mTimeoutTick->Init(this, 1000, nsITimer::TYPE_REPEATING_SLACK); diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index a2c88c4028..5f24db0ede 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -492,8 +492,15 @@ private: //------------------------------------------------------------------------- ReentrantMonitor mReentrantMonitor; + // This is used as a flag that we're shut down, and no new events should be + // dispatched. nsCOMPtr mSocketThreadTarget; + Atomic mIsShuttingDown; + + //------------------------------------------------------------------------- + // NOTE: these members are only accessed on the socket transport thread + //------------------------------------------------------------------------- // connection limits uint16_t mMaxConns; uint16_t mMaxPersistConnsPerHost; @@ -501,11 +508,6 @@ private: uint16_t mMaxRequestDelay; // in seconds uint16_t mMaxPipelinedRequests; uint16_t mMaxOptimisticPipelinedRequests; - Atomic mIsShuttingDown; - - //------------------------------------------------------------------------- - // NOTE: these members are only accessed on the socket transport thread - //------------------------------------------------------------------------- bool ProcessPendingQForEntry(nsConnectionEntry *, bool considerAll); bool IsUnderPressure(nsConnectionEntry *ent,