4

When you close your browser while you have an active websocket connection, the following behavior seems to depend on the browser:

  • Firefox: Triggers onClose().
  • Internet Explorer: Triggers onClose().
  • Chrome: Will trigger onErr(), the throwable doesn't seem to include a CloseReason.

    01:22:47,428 ERROR [stderr] (default task-5) java.nio.channels.ClosedChannelException 01:22:47,429 ERROR [stderr] (default task-5) at io.undertow.server.protocol.framed.AbstractFramedChannel.receive(AbstractFramedChannel.java:253) 01:22:47,429 ERROR [stderr] (default task-5) at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:20) 01:22:47,429 ERROR [stderr] (default task-5) at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:15) 01:22:47,429 ERROR [stderr] (default task-5) at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) 01:22:47,429 ERROR [stderr] (default task-5) at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:615) 01:22:47,429 ERROR [stderr] (default task-5) at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:601) 01:22:47,429 ERROR [stderr] (default task-5) at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92) 01:22:47,429 ERROR [stderr] (default task-5) at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66) 01:22:47,429 ERROR [stderr] (default task-5) at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:87) 01:22:47,430 ERROR [stderr] (default task-5) at org.xnio.nio.WorkerThread.run(WorkerThread.java:531)

I tried to make a workaround, catching the onbeforeunload event....

window.onbeforeunload = function () {
            console.log("closing window");
            return null;
        }

...but it looks like, this is not possible with current versions of Chrome.

Why does Chrome trigger onError(), instead of closing the connection? I don't think it's an error, when a user is closing the browser window. Mostly there is no more need for the webservice, so the user will close the window.

Also, see this thread: Should WebSocket.onclose be triggered by user navigation or refresh?

I have to call OnClose() if onError() is triggered, because I can't close the connection when a Chrome user closes the window.

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

    }

I'm not sure if every event, that triggers onError() should close the connection....

Community
  • 1
  • 1
Lama
  • 2,886
  • 6
  • 43
  • 59
  • How did you resolve this issue? – daydreamer Jul 15 '14 at 20:21
  • It seems this problem is caused by the interpration of the standard by browsers and frameworks. There is no real solution, but to keep in mind how the browsers and frameworks will react during a connection. E.G. sometimes the function annotated by @OnOpen will be executed, even if the connection is corrupt (handshake failed). – Lama Jul 17 '14 at 13:49
  • but did you find any workaround which worked for you? – daydreamer Jul 17 '14 at 15:41
  • at this moment I just run the same methods within the OnError and the OnClose methods... – Lama Jul 18 '14 at 13:21

0 Answers0