anish ratnawat
anish ratnawat

Reputation: 101

Is @OnWebSocketClose always gets called ? I am getting @onwebsocketerror and @onwebsocketclose is not getting called

Is @onwebsocketclose always gets called ? I am getting @onwebsocketerror and @onwebsocketclose is not getting called .

 There might be some broken pipe connection .
 StackTrace :
org.eclipse.jetty.io.EofException: null
    at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:283) ~[application.jar:?]
    at org.eclipse.jetty.io.WriteFlusher.flush(WriteFlusher.java:422) ~[application.jar:?]
    at org.eclipse.jetty.io.WriteFlusher.completeWrite(WriteFlusher.java:378) ~[application.jar:?]
    at org.eclipse.jetty.io.ChannelEndPoint$3.run(ChannelEndPoint.java:132) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:367) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:782) ~[application.jar:?]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:918) ~[application.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]
Caused by: java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:1.8.0_111]
    at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[?:1.8.0_111]
    at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[?:1.8.0_111]
    at sun.nio.ch.IOUtil.write(IOUtil.java:65) ~[?:1.8.0_111]
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)~[?:1.8.0_111]
    at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:261) ~[application.jar:?]

Upvotes: 1

Views: 911

Answers (1)

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49545

the Close method is called for WebSocket handshake completion or abnormal completion.

I/O errors, idle timeouts, harsh disconnects, and other errors are on the Error method.

Any event on onClose() or onError() signals the end of your session.

Exceptional closures (throwables) are racy on which of the 2 application event methods are called.

Some behaviors:

  • We try to notify onClose() only once.
  • We try to notify onError() only once.
  • If onClose() is called, onError() will not be called.
  • If onError() is called, onClose() will not be called.
  • If the closure is determined to be from an exception, then:
    1. the exception is logged on DEBUG level
    2. the application onError() is called (if not already called)
    3. the close frame is queued (if not already sent or queued)
    4. the on success or failure of close frame send, the connection is disconnected. (there is no wait for the remote close frame in this exceptional case)

Failures during handshake are ...

  • On a WebSocket Client the connect will fail with an exception (this could be reported as a failure when attempting to get the Session object from the connect future)
  • On a WebSocket Server the connect will not succeed, no WebSocket Session is created, no Endpoint is created, no onOpen() is called.

Upvotes: 1

Related Questions