From 7fab5ebd115f6c6d3a3cdcefcbf9fad5be03a6ee Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 19 Nov 2022 14:06:18 +0000 Subject: [PATCH] WebSocketChannel::CleanupConnection should run on the socket thread --- netwerk/protocol/websocket/WebSocketChannel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index f94c1d9ca9..679252500f 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -2313,6 +2313,16 @@ WebSocketChannel::CleanupConnection() { LOG(("WebSocketChannel::CleanupConnection() %p", this)); + // This should run on the Socket Thread to prevent potential races. + bool onSocketThread; + nsresult rv = mSocketThread->IsOnCurrentThread(&onSocketThread); + if (NS_SUCCEEDED(rv) && !onSocketThread) { + mSocketThread->Dispatch( + NewRunnableMethod(this, &WebSocketChannel::CleanupConnection), + NS_DISPATCH_NORMAL); + return; + } + if (mLingeringCloseTimer) { mLingeringCloseTimer->Cancel(); mLingeringCloseTimer = nullptr;