summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2022-03-08 19:47:29 +0000
committerMoonchild <moonchild@palemoon.org>2022-03-09 11:42:48 +0000
commitec9c98028fe5456227067dd7d463c3a4375e9377 (patch)
tree95ad616dee4d5b6d42cfdb1dd05bb5da1b5546c1
parent89c1e207478f03ff0c8b3d3de5c50e3809cd16a6 (diff)
downloaduxp-ec9c98028fe5456227067dd7d463c3a4375e9377.tar.gz
[Network] Only call nsWSAdmissionManager::ConnectNext on the main thread.
-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 85a822806b..f94c1d9ca9 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);
}
}