summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-03-08 19:47:29 +0000
committerMoonchild <moonchild@palemoon.org>2022-04-03 01:13:51 +0200
commite428fb2fad060151b84737b41c710e6bb1b9d038 (patch)
tree2ec84ffe601edfdb1ba35018ff07437f042fef44
parent01782d03bc1c04a39a27094faa6ee1f7f0a3680a (diff)
downloaduxp-e428fb2fad060151b84737b41c710e6bb1b9d038.tar.gz
[Network] Only call nsWSAdmissionManager::ConnectNext on the main thread.
-rw-r--r--netwerk/protocol/websocket/WebSocketChannel.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp
index 952c0d5ee5..45fafcc825 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);
}
}