Hello, We have a random problem with Apache Tomcat/9.0.100 in Windows, JDK 11.0.13. We have seen this problem only once so far. Problem is that WebSocket connection is apparently closed but there is no callback to @OnClose handler, which is implemented in @ServerEndpoint class. Then this WebSocket session lives forever, until Tomcat is restarted. When our application tries to send async message to this WebSocket, then it always fails with this error:
java.io.IOException: An established connection was aborted by the software in your host machine at java.base/sun.nio.ch.SocketDispatcher.write0(Native Method) at java.base/sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51) at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:113) at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:79) at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:50) at java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:462) at org.apache.tomcat.util.net.SecureNioChannel.flush(SecureNioChannel.java:125) at org.apache.tomcat.util.net.SecureNioChannel.write(SecureNioChannel.java:883) at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper$NioOperationState.run(NioEndpoint.java:1684) at org.apache.tomcat.util.net.SocketWrapperBase$OperationState.start(SocketWrapperBase.java:1077) at org.apache.tomcat.util.net.SocketWrapperBase.vectoredOperation(SocketWrapperBase.java:1496) at org.apache.tomcat.util.net.SocketWrapperBase.write(SocketWrapperBase.java:1422) at org.apache.tomcat.util.net.SocketWrapperBase.write(SocketWrapperBase.java:1393) at org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer.doWrite(WsRemoteEndpointImplServer.java:171) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.writeMessagePart(WsRemoteEndpointImplBase.java:520) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:411) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$TextMessageSendHandler.write(WsRemoteEndpointImplBase.java:844) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendStringByCompletion(WsRemoteEndpointImplBase.java:212) at org.apache.tomcat.websocket.WsRemoteEndpointAsync.sendText(WsRemoteEndpointAsync.java:46) I just implemented possible workaround for this problem by calling close() on the WebSocket when this IOException happens in the sendText() callback. Now I am asking, do you think that this workaround will fix the problem, if it ever happens again? javax.websocket.Session#close() /** * Close the current conversation with a normal status code and no reason phrase. * * @throws IOException if there was a connection error closing the connection. */ @Override void close() throws IOException; Another problem with this WebSocket is that isOpen() always returns true. javax.websocket.Session#isOpen /** * Return true if and only if the underlying socket is open. * * @return whether the session is active. */ boolean isOpen(); Thanks, -Harri