Skip to content

Retry when WebSocket connection not established (no onopen event) #41

Description

@asmaradiya7648

Currently, the WebSocket transport retries only when the connection is closed or fails after being established.

However, sometimes the initial WebSocket connection never succeeds — for example, when the browser cannot reach the server (network issue, DNS failure, or dropped SYN).
In such cases, the onopen event is never emitted, and the retry logic is never triggered, leaving the app stuck waiting forever.

Here’s the relevant section in the code:

`
this._ws.onopen = () =>
{
if (this._closed)
return;

wasConnected = true;

// Emit 'open' event.
this.safeEmit('open');

};
`

If the connection attempt never reaches this point (no onopen), there’s currently no mechanism to retry.

💡 Expected behavior

If the WebSocket connection is not established within a reasonable timeout (for example, 5 seconds), the library should automatically retry — just like it already does for onclose or onerror events.

This would make the connection logic more robust in real-world network conditions.

🔍 Example use case

When using this library in the browser, sometimes the WebSocket handshake never completes (e.g., network hiccup or local firewall).
Because no open or close event fires, the client stays stuck and never reconnects.

It would be helpful if the library could automatically:

Detect that onopen didn’t fire within N seconds.

Trigger a reconnect attempt (using the same retry logic as in onclose).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions