Skip to content

WebSockets do not fire 'close' event if the connection failed to be established #3546

@marximimus

Description

Consider the following code:

const webSocket = new undici.WebSocket("wss://invalid-domain.example.com/");
webSocket.onopen = () => { console.log("open"); };
webSocket.onclose = () => { console.log("close"); };
webSocket.onerror = () => { console.log("error"); };

It outputs:

error

However, a standard-compliant WebSocket implementation would output:

error
close

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:

When the WebSocket connection is closed, possibly cleanly, the user agent must queue a task to run the following substeps:
...
3. Fire an event named close at the WebSocket object.

This bug is reproducible on commit 4b8958a.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions