RESOLVED FIXED287784
Using WebSocket in a WebWorker can cause the entire Worker to freeze
https://bugs.webkit.org/show_bug.cgi?id=287784
Summary Using WebSocket in a WebWorker can cause the entire Worker to freeze
bennett.chen
Reported 2025-02-16 23:31:18 PST
Created attachment 474243 [details] This demo can be stably reproduced on some machines Using WebSocket in a WebWorker can cause the entire Worker to freeze. By viewing the WebKit code, it was found that if the server disconnects while the client WebSocket is sending data, the send operation may get blocked, causing the Worker to become unresponsive. void WorkerThreadableWebSocketChannel::Peer::send(CString&& message) { ASSERT(isMainThread()); - if (!m_mainWebSocketChannel) - return; - - ThreadableWebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->send(WTFMove(message)); + ThreadableWebSocketChannel::SendResult sendRequestResult = ThreadableWebSocketChannel::SendResult::SendFail; + + if (!m_mainWebSocketChannel){ + printf("<<<<< WebSocketChannel::Peer::send m_mainWebSocketChannel is null peer %p , workerClientWrapper %p \n ",this,m_workerClientWrapper.ptr()); + // If it returns directly here, WebSocket send will be blocked. + // return; + }else{ + sendRequestResult = m_mainWebSocketChannel->send(WTFMove(message)); + } ScriptExecutionContext::postTaskForModeToWorkerOrWorklet(m_workerContextIdentifier, [workerClientWrapper = m_workerClientWrapper, sendRequestResult](ScriptExecutionContext&) mutable { workerClientWrapper->setSendRequestResult(sendRequestResult); }, m_taskMode); }
Attachments
This demo can be stably reproduced on some machines (59.83 KB, application/zip)
2025-02-16 23:31 PST, bennett.chen
no flags
worker websocket test demo (60.54 KB, application/zip)
2025-02-19 18:25 PST, bennett.chen
no flags
test result (874.18 KB, image/jpeg)
2025-02-19 19:05 PST, bennett.chen
no flags
bennett.chen
Comment 1 2025-02-19 02:05:23 PST
Any comments?
Radar WebKit Bug Importer
Comment 2 2025-02-19 10:13:01 PST
bennett.chen
Comment 3 2025-02-19 18:25:22 PST
Created attachment 474306 [details] worker websocket test demo update demo
bennett.chen
Comment 4 2025-02-19 19:05:58 PST
Created attachment 474307 [details] test result
EWS
Comment 5 2025-02-21 09:36:39 PST
Committed 290802@main (502bfe7b3124): <https://commits.webkit.org/290802@main> Reviewed commits have been landed. Closing PR #40972 and removing active labels.
EWS
Comment 6 2025-04-11 12:53:42 PDT
Committed 289651.422@safari-7621-branch (1ad118aeb3f3): <https://commits.webkit.org/289651.422@safari-7621-branch> Reviewed commits have been landed. Closing PR #2984 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.