java websocket EOFException occur

12.1k views Asked by At

I am using a Java websocket but I'm getting an error I don't understand.

When the server gets either a RuntimeException or NullPointerException etc., the onError method is called.

After that(finished onError method), the onError method is called again. After the second time, EOFException occurs continuously.

Do you have any idea why EOFException is occurring after onError method?

Here is my error log:

java.io.EOFException
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1267)
    at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.isReadyForRead(NioEndpoint.java:1176)
    at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:58)
    at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148)
    at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:788)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1485)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
2

There are 2 answers

0
Vincent Gerris On

This happens usually when the client connection to the server is disconnected. That can happen for a variety of reasons, often a timeout set on any load balancer that is in between or the tomcat settings, but it could also be the client and any network interruption in between client and server.

Don't forget to handle the exception in the OnError method, typically you want to close the session there.

0
Anas Ben Mansour On

I had the same issue that you did. If you use NGINGX to redirect websocket requests, you have to increase the proxy_read_timeout value. Otherwise, the connection will be closed after 60 seconds (by default).