emscripten-core / emscripten-core/emscripten

Catch WebSocket JS exceptions in library_websocket.js

Open
#21,713 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

**Version of emscripten/emsdk:**
Please include the output `emcc -v` here

I am using the latest Pyodide master version that appears to be using Emscripten version 3.1.52

I am receiving errors such as the following console message when using WebSockets:

```
pyodide.asm.js:9 Uncaught DOMException: Failed to execute 'close' on 'WebSocket': The close code must be either 1000, or between 3000 and 4999. 0 is neither.
at _emscripten_websocket_close (http://localhost:8000/robotraconteur_pyodide/pyodide/pyodide.asm.js:9:519374)
at wasm://wasm/04206a8e:wasm-function[8899]:0xaba21d
at invoke_vi (http://localhost:8000/robotraconteur_pyodide/pyodide/pyodide.asm.js:9:1214419)
at wasm://wasm/04206a8e:wasm-function[8893]:0xab775b
at socket.onclose (http://localhost:8000/robotraconteur_pyodide/pyodide/pyodide.asm.js:9:516980)
```

```
WebSocket is already in CLOSING or CLOSED state.
```

And then a long WASM stack trace that I can't seem to copy out of the log for some reason.

It appears that the `library_websocket.js` functions are not catching JS exceptions generated by WebSocket functions, and are instead letting the JS exceptions pass back into WASM where they can't be caught. This is resulting in my entire application crashing. While my software clearly has some problems with how it is using WebSockets, if the error return was being handled correctly it would be able to recover. They JS exceptions should be caught, and an error code gracefully returned.

This is something I can work on in the next few weeks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.