12
votes

I am using Netty websockets and everything seems to work fine except this minor issue :

If I close the browser / tab of the js websocket client , the websocket connection is automatcally closed when using Mozilla firefox (currently using firefox 14) but the same thing does not happen in Chrome 20/21.

Anyone seen a similar issue / can anyone tell why is the connection not closed automatically ?

3

3 Answers

6
votes

I guess I should have checked this earlier in the chromium bug section but I was not sure if it is a bug. It has been reported earlier by someone and a chromium bug already exists :

Issue 51687 : WebSocket: Send close with code 1001 on reload / tab close

Update : Someone has submitted a patch to fix this issue, can be seen in the above link.

1
votes

This may not be right, but I cannot post a comment to your question. Chrome/Chromium does not really close if you have an App running and have selected "Continue running background apps when Chromium is closed" from Settings-->Under the hood.

It may be that it treats the websocket connection as an app. Try looking at your running processes and kill any chrome/chromium process you find.

Again, this is just speculation on my part.

0
votes

Chrome doesn't close the connection, when a user will close the window or browser. It will trigger an Error event.

A possible workaround could look like this:

  @OnError
    public void onErr(Throwable t) {
        onClose(this.container.getWsSession(), null);

    }

But this will close the connection every time, an Error is triggered. You may wan't to check the throwable, before closing the connection by yourself.

For more discussion, please join this question:

Websocket: Closing browser triggers onError() in chrome but onClose() event in Firefox