Skip to content

Commit 8171579

Browse files
Esteban Ordanoeordano
authored andcommitted
fix(NQE): WebSocketApi.js send() no-ops on CLOSING/CLOSED (spec)
UNITY-EXPLORER-NQE (904 evts/15 users): ClearScript ScriptEngineException "WebSocket state is 3, cannot send data" bubbling out of SceneFacade.UpdateLoopAsync. The scene-facing JS WebSocket shim threw on any non-OPEN state; a scene calling send() after close (state 3 = CLOSED) threw once per tick and each was reported to Sentry. Per the WHATWG spec, send() on CLOSING/CLOSED silently discards; only CONNECTING is an error. Make CLOSING/CLOSED a no-op. NOTE: StreamingAssets JS ships with the build — takes effect next client build, not hot-patchable. Unverified. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Production evidence (decentraland Sentry, archive snapshot 2026-07-17): - UNITY-EXPLORER-NQE: 652 events / 14 users, last seen 2026-07-16
1 parent 8584628 commit 8171579

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

Explorer/Assets/StreamingAssets/Js/Modules/WebSocketApi.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class WebSocket {
4747
const thisReadyState = this.readyState;
4848
// console.log("WebSocket.send is called", data.constructor.name, `State is ${thisReadyState}`);
4949

50+
// Per the WHATWG WebSocket spec, send() on a CLOSING/CLOSED socket must NOT throw — the data is
51+
// silently discarded. Throwing on CLOSED bubbled out of the scene update loop and was reported to
52+
// Sentry once per tick by misbehaving scenes (UNITY-EXPLORER-NQE: "WebSocket state is 3, cannot
53+
// send data"). Only a still-CONNECTING socket remains an error.
54+
if (thisReadyState === WebSocket.CLOSING || thisReadyState === WebSocket.CLOSED) {
55+
return;
56+
}
57+
5058
if (thisReadyState !== WebSocket.OPEN) {
5159
const errorMessage = `WebSocket state is ${thisReadyState}, cannot send data`;
5260
throw new Error(errorMessage);

0 commit comments

Comments
 (0)