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

Unable to use nhooyr/websocket in WASM running in Node.js: nhooyr/websocket should process 'error' event #400

Closed
sza-1 opened this issue Aug 7, 2023 · 2 comments
Labels
Milestone

Comments

@sza-1
Copy link

sza-1 commented Aug 7, 2023

Probably websocket#Conn.init should call c.ws.OnError to subscribe on and process WebSocket#error event.

The issue is the following:

https://github.com/websockets/ws is the most popular WebSocket implementation for the Node.js. It is based on EventEmitter, which throws an exception on any unhandled connection error. Actually it emits error event and then close event. If there is no event listener for error event, then EventEmitter throws an exception and Node.js crashes by default (this behaviour may be fixed with node:domain, but it is deprecated in Node.js 20.5.0). Writers of JavaScript code unable to add an error listener, since nhooyr/websocket creates WebSocket object internally, so it makes nhooyr/websocket pretty unusable in Node.js in case of invalid WSS URL or any transport error.

Probably adding of websocket#Conn.releaseOnClose and calling c.ws.OnError should fix the issue.

Found on Node.js 20.5.0, websockets/ws 8.13.0 and nhooyr/websocket 1.8.7.

@nhooyr nhooyr added the bug label Sep 28, 2023
@nhooyr nhooyr added this to the v1.8.8 milestone Sep 28, 2023
@nhooyr
Copy link
Owner

nhooyr commented Sep 28, 2023

Thanks for reporting. Will fix in next release.

nhooyr added a commit that referenced this issue Oct 19, 2023
@nhooyr
Copy link
Owner

nhooyr commented Oct 19, 2023

Fixed in dev. Let me know if it looks good.

@nhooyr nhooyr closed this as completed Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants