-
Notifications
You must be signed in to change notification settings - Fork 572
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
WebSockets do not fire 'close' event if the connection failed to be established #3546
Comments
Is it connected to #3506 and maybe already fixed in main but not released yet? |
The Code import { WebSocket } from 'undici';
const webSocket = new WebSocket("wss://invalid-domain.example.com/");
webSocket.onopen = () => { console.log("open"); };
webSocket.onclose = () => { console.log("close"); };
webSocket.onerror = () => {
console.log("error");
console.log("readyState", webSocket.readyState);
}; Console output
On |
Trying the code in a local HTML page on a browser, a
|
This can be fixed by changing the the following. undici/lib/web/websocket/websocket.js Lines 527 to 533 in 4b8958a
First, adding a And then changing this line undici/lib/web/websocket/websocket.js Line 669 in 4b8958a
to I can open a PR to fix with the mentioned changes if it is considered acceptable fix. |
* see #3546, #3548 & #3565 Signed-off-by: eXhumer <[email protected]>
Consider the following code:
It outputs:
However, a standard-compliant WebSocket implementation would output:
This is because establish a WebSocket connection algorithm would invoke fail the WebSocket Connection algorithm in step 11.1, which would Close the WebSocket Connection. The WebSocket standard states:
This bug is reproducible on commit 4b8958a.
The text was updated successfully, but these errors were encountered: