From bcbe73119f7746136f1bf89ba618d123964a79c3 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 20 Dec 2023 21:41:00 +0100 Subject: [PATCH] [dom] Better handling of aborted websocket workers. Catch the case where we are in worker-shutdown but are still connecting and make filing and closing connections a bit more robust with a RefPtr. --- dom/base/WebSocket.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/dom/base/WebSocket.cpp b/dom/base/WebSocket.cpp index fe06bc93a4..6c8154a35d 100644 --- a/dom/base/WebSocket.cpp +++ b/dom/base/WebSocket.cpp @@ -2548,16 +2548,22 @@ WebSocket::Close(const Optional& aCode, return; } - // If the webSocket is not closed we MUST have a mImpl. - MOZ_ASSERT(mImpl); + // If we don't have mImpl, we are in a shutting down worker where we are still + // in CONNECTING state, but already disconnected internally. + if (!mImpl) { + MOZ_ASSERT(readyState == CONNECTING); + SetReadyState(CLOSING); + return; + } + RefPtr impl = mImpl; if (readyState == CONNECTING) { - mImpl->FailConnection(closeCode, closeReason); + impl->FailConnection(closeCode, closeReason); return; } MOZ_ASSERT(readyState == OPEN); - mImpl->CloseConnection(closeCode, closeReason); + impl->CloseConnection(closeCode, closeReason); } //-----------------------------------------------------------------------------