Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on Deno when WebSocket abruptly closes #2939

Merged
merged 3 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/wasm-node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
9 changes: 8 additions & 1 deletion bin/wasm-node/javascript/src/index-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/paritytech/smoldot/issues/2937>.
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
Expand Down