1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 05:46:58 +00:00

[Network] Only call nsWSAdmissionManager::ConnectNext on the main thread.

This commit is contained in:
Moonchild
2022-03-08 19:47:29 +00:00
committed by roytam1
parent 66ae44b71f
commit 398cb98445
+37 -14
View File
@@ -429,23 +429,46 @@ public:
}
}
if (aChannel->mConnecting) {
MOZ_ASSERT(NS_IsMainThread(), "not main thread");
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;
}
// 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?");
nsWSAdmissionManager::ContinueOnStopSession(channel, reason);
}));
}
}
sManager->RemoveFromQueue(aChannel);
static void ContinueOnStopSession(WebSocketChannel* aChannel,
nsresult aReason) {
sLock.AssertCurrentThreadOwns();
MOZ_ASSERT(NS_IsMainThread(), "not main thread");
bool wasNotQueued = (aChannel->mConnecting != CONNECTING_QUEUED);
LOG(("Websocket: changing state to NOT_CONNECTING"));
aChannel->mConnecting = NOT_CONNECTING;
if (wasNotQueued) {
sManager->ConnectNext(aChannel->mAddress);
}
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);
}
}