Bug 1752100 - Make sure nsWSAdmissionManager::ConnectNext is called on main thread, r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D137267
This commit is contained in:
Kershaw Chang 2022-01-31 11:11:53 +00:00
Родитель b023d4c351
Коммит f73fac8381
1 изменённых файлов: 37 добавлений и 14 удалений

Просмотреть файл

@ -399,14 +399,38 @@ class nsWSAdmissionManager {
}
}
if (aChannel->mConnecting) {
if (NS_IsMainThread()) {
ContinueOnStopSession(aChannel, aReason);
} else {
NS_DispatchToMainThread(NS_NewRunnableFunction(
"nsWSAdmissionManager::ContinueOnStopSession",
[channel = RefPtr{aChannel}, 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");
// 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.
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);
@ -417,7 +441,6 @@ class nsWSAdmissionManager {
sManager->ConnectNext(aChannel->mAddress, aChannel->mOriginSuffix);
}
}
}
static void IncrementSessionCount() {
StaticMutexAutoLock lock(sLock);