summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-03-08 19:47:29 +0000
committerMoonchild <moonchild@palemoon.org>2022-03-21 13:25:16 +0000
commitab3c367a387ea95e35ecda5fd7a91fdf311c2407 (patch)
tree86b19ae822c9fbd6a14e2ce13b7dd85f8c77bfcf /system
parent56534c05963b925da8338e50cba5a266902c8b74 (diff)
downloadaura-central-ab3c367a387ea95e35ecda5fd7a91fdf311c2407.tar.gz
[Network] Only call nsWSAdmissionManager::ConnectNext on the main thread.
Diffstat (limited to 'system')
-rw-r--r--system/network/protocol/websocket/WebSocketChannel.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/system/network/protocol/websocket/WebSocketChannel.cpp b/system/network/protocol/websocket/WebSocketChannel.cpp
index 85a822806..f94c1d9ca 100644
--- a/system/network/protocol/websocket/WebSocketChannel.cpp
+++ b/system/network/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);
}
}