diff options
author | Moonchild <moonchild@palemoon.org> | 2022-03-08 19:47:29 +0000 |
---|---|---|
committer | Moonchild <moonchild@palemoon.org> | 2022-05-30 08:13:03 +0000 |
commit | edd7cd7d870f97ba85f4c97b5d83d8e5e544bdc0 (patch) | |
tree | daf618214159e112995048b2f8bdbd516444120d /netwerk/protocol | |
parent | 23327d721306820f392814525d40036b47cf600d (diff) | |
download | uxp-edd7cd7d870f97ba85f4c97b5d83d8e5e544bdc0.tar.gz |
[Network] Only call nsWSAdmissionManager::ConnectNext on the main thread.
Diffstat (limited to 'netwerk/protocol')
-rw-r--r-- | netwerk/protocol/websocket/WebSocketChannel.cpp | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 85a822806b..f94c1d9ca9 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -429,23 +429,46 @@ public: } } - if (aChannel->mConnecting) { - MOZ_ASSERT(NS_IsMainThread(), "not main thread"); - - // Only way a connecting channel may get here w/o failing is if it was - // closed with GOING_AWAY (1001) because of navigation, tab close, etc. - MOZ_ASSERT(NS_FAILED(aReason) || - aChannel->mScriptCloseCode == CLOSE_GOING_AWAY, - "websocket closed while connecting w/o failing?"); - - sManager->RemoveFromQueue(aChannel); - - bool wasNotQueued = (aChannel->mConnecting != CONNECTING_QUEUED); - LOG(("Websocket: changing state to NOT_CONNECTING")); - aChannel->mConnecting = NOT_CONNECTING; - if (wasNotQueued) { - sManager->ConnectNext(aChannel->mAddress); - } + if (NS_IsMainThread()) { + ContinueOnStopSession(aChannel, aReason); + } else { + RefPtr<WebSocketChannel> threadChannel = aChannel; + NS_DispatchToMainThread(NS_NewRunnableFunction( + [channel = threadChannel, reason = aReason]() { + StaticMutexAutoLock lock(sLock); + if (!sManager) { + return; + } + + nsWSAdmissionManager::ContinueOnStopSession(channel, reason); + })); + } + } + + static void ContinueOnStopSession(WebSocketChannel* aChannel, + nsresult aReason) { + sLock.AssertCurrentThreadOwns(); + MOZ_ASSERT(NS_IsMainThread(), "not main thread"); + + if (!aChannel->mConnecting) { + return; + } + + // Only way a connecting channel may get here w/o failing is if it + // was closed with GOING_AWAY (1001) because of navigation, tab + // close, etc. + MOZ_ASSERT( + NS_FAILED(aReason) || aChannel->mScriptCloseCode == CLOSE_GOING_AWAY, + "websocket closed while connecting w/o failing?"); + Unused << aReason; + + sManager->RemoveFromQueue(aChannel); + + bool wasNotQueued = (aChannel->mConnecting != CONNECTING_QUEUED); + LOG(("Websocket: changing state to NOT_CONNECTING")); + aChannel->mConnecting = NOT_CONNECTING; + if (wasNotQueued) { + sManager->ConnectNext(aChannel->mAddress); } } |