diff --git a/bin/wasm-node/CHANGELOG.md b/bin/wasm-node/CHANGELOG.md index a5efea828b..c17c71c24a 100644 --- a/bin/wasm-node/CHANGELOG.md +++ b/bin/wasm-node/CHANGELOG.md @@ -10,6 +10,7 @@ ### Fixed +- Fix panic on Deno when a WebSocket connection abruptly closes. ([#2939](https://github.com/paritytech/smoldot/pull/2939)) - Fix errors showing in the browser's console about WebSockets being already in the CLOSING or CLOSED state. ([#2925](https://github.com/paritytech/smoldot/pull/2925)) - No longer panic when a WebRTC connection fails to open due to the browser calling callbacks in an unexpected order. ([#2936](https://github.com/paritytech/smoldot/pull/2936)) diff --git a/bin/wasm-node/javascript/src/index-deno.ts b/bin/wasm-node/javascript/src/index-deno.ts index ea97df4789..ab5c7af510 100644 --- a/bin/wasm-node/javascript/src/index-deno.ts +++ b/bin/wasm-node/javascript/src/index-deno.ts @@ -228,7 +228,14 @@ function connect(config: ConnectionConfig, forbidTcp: boolean, forbidWs: boolean send: (data: Uint8Array): void => { if (connection.ty == 'websocket') { // WebSocket - connection.socket.send(data); + // The WebSocket library that we use seems to spontaneously transition connections + // to the "closed" state but not call the `onclosed` callback immediately. Calling + // `send` on that object throws an exception. In order to avoid panicking smoldot, + // we thus absorb any exception thrown here. + // See also . + try { + connection.socket.send(data); + } catch(_error) {} } else { // TCP // TODO: at the moment, sending data doesn't have any back-pressure mechanism; as such, we just buffer data indefinitely