-
Notifications
You must be signed in to change notification settings - Fork 576
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
WebSocket: "close" is not emitted on error #3697
Comments
I'm also open to contributing a fix to this if we conclude that it's indeed an issue! Would appreciate guidance with tests during the code review. |
Imho it was already fixed by @KhafraDev via #3628 and #3651 . Just not backported?! |
Oh, that sounds nice! I'm trying that on Node.js v18, I believe. I'd love to have a backport to that version. |
backporting to v6 will be difficult because websocket has had significant rewrites |
@KhafraDev, understandable. Is v22 the minimal to use to get this fix then? (Undici v7) |
@KhafraDev There is also issue with let ws = new WebSocket('wss://example.com/non-existing-url')
ws.onerror = () => console.log('ERROR!')
ws.onclose = () => console.log('CLOSE!')
setTimeout(()=>console.log(ws.readyState),7000) Undici@main Output:
Firefox Output:
Safari Output:
chrome Output:
|
@fawazahmed0 I have opened a PR with a fix, thanks. |
Bug Description
When a WebSocket connection is closed due to an error, the
close
event doesn't get emitted.Reproducible By
Run this in Node.js REPL (assumes
undici
is installed):Expected Behavior
The WebSocket instance must dispatch two events in the following order:
Actual behavior
It doesn't. Only the error event gets dispatched. The close event never gets dispatched, which I believe to be incorrect.
Logs & Screenshots
I can also verify that the browser implementation of WebSocket behaves correctly:
Environment
I believe the environment is irrelevant here.
Additional context
error
event on MDN:The text was updated successfully, but these errors were encountered: