Skip to content

WebSocket is closed before the connection is established #353

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

Closed
shinigami1992 opened this issue Jan 9, 2017 · 7 comments
Closed

WebSocket is closed before the connection is established #353

shinigami1992 opened this issue Jan 9, 2017 · 7 comments

Comments

@shinigami1992
Copy link

shinigami1992 commented Jan 9, 2017

Hi guys, thank you for your awesome library.

I've used sockjs-client for connecting my web app to a spring websocket web server, the problem is that when i refresh related browser page, sometimes (about 5%) this error will happen.

WebSocket connection to 'ws://localhost:4568/ws/379/lsb17jhg/websocket?X....' failed: WebSocket is closed before the connection is established

maybe useful to say that I didnt call disconnect or close anywhere in my code.

Thank you.

@brycekahle
Copy link
Contributor

What browser? Was the WebSocket connected when you refreshed? If not, this could just be a browser warning.

@Southpaw17
Copy link

Have you tried ending the socket connection before refreshing the page? There is a similar issue to this on the Primus Issue Tracker: primus/primus#398

The suggested workaround there is to do the following:

window.addEventListener("beforeunload", function (event) { primus.end(); });

@shinigami1992
Copy link
Author

shinigami1992 commented Jan 26, 2017

@brycekahle Google Chrome on OSX. Yeah when i refresh the page, it will connect.

@Southpaw17 Thanks for your hint. What's equivalent code in sockjs-client? Should I use Primus library to overcome this issue?

Thanks.

@brycekahle
Copy link
Contributor

@majeedsan It does appear we will close the websocket on unload without ensuring that the open event has fired.

this.unloadRef = utils.unloadAdd(function() {
debug('unload');
self.ws.close();
});

@brycekahle
Copy link
Contributor

Unfortunately we don't have any other way to stop the websocket from continuing the connection attempt (other than relying on the browser to stop it) on page unload. I think it is safe to ignore the browser warning. What do you think?

@ryanbrandenburg
Copy link

We have the same problem (though through a couple layers of indirection because we're seeing it from angular webpack) but it happens 100% of the time.

Repro steps:

  1. Install a 3.0 preview of dotnet.
  2. dotnet new angular
  3. dotnet run from within the new template.
  4. Visit the page and check the console to view the warning (error on Firefox).

@github-actions
Copy link

github-actions bot commented Aug 3, 2020

This issue has been inactive for 30 days. It will be in closed in 5 days without any new activity.

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

No branches or pull requests

4 participants