12

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 ?

Rndm
  • 6,710
  • 7
  • 39
  • 58

3 Answers3

6

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.

Rndm
  • 6,710
  • 7
  • 39
  • 58
1

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.

Gabriel Samfira
  • 2,675
  • 1
  • 17
  • 19
  • No , I don't think so as even after disabling that option , the websocket connection is not closed on closing the tab. – Rndm Aug 01 '12 at 09:53
  • It may be a bug in Chrome then. You should open a bug report with the chromium project. – Gabriel Samfira Aug 01 '12 at 09:55
  • I posted it here so as to confirm if someone else has seen it or there is some option available to solve it. – Rndm Aug 01 '12 at 09:56
0

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

Community
  • 1
  • 1
Lama
  • 2,886
  • 6
  • 43
  • 59