Skip to content

Conversation

@Al-ex-ei
Copy link

Problem

When webSocketFactory returns an already open WebSocket, the onopen callback never triggers and CONNECT frame is not sent.

Solution

Added readyState check: if already open, call the handler immediately; otherwise set onopen.

@Al-ex-ei
Copy link
Author

Al-ex-ei commented Dec 8, 2025

@kum-deepak take a look please

@kum-deepak
Copy link
Member

Many thanks for the PR. I understand how it works. I also know why it is needed.

I will merge it after writing test cases to cover it.

I am curious, how did you encounter this race condition? I will add those to the documentation or FAQs.

@Al-ex-ei
Copy link
Author

It's a bit unusual case.

I was optimizing the time to Interactive metric for my app. Receiving data via stomp was the longest part of loading for a significant number of users.

So I decided to load the stompjs library and create the WebSocket connection in parallel. When stompjs is ready, I create a client and provide it with the WebSocket, but the WebSocket state could be different in different cases (different connection speeds, network conditions, locations, etc.)

In some cases, the WebSocket is already in the OPEN

@kum-deepak
Copy link
Member

I have added a test case, see

it('Connect with a websocket that is already open', function (done) {

@kum-deepak
Copy link
Member

Merged and published as v7.3.0-beta.2.

@kum-deepak kum-deepak closed this Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants