One more thing, we are using Tomcat native.dll:

19:39:09.263 INF> (main) 
(org.apache.catalina.core.AprLifecycleListener#lifecycleEvent) Loaded Apache 
Tomcat Native library [1.3.1] using APR version [1.7.4].
19:39:09.263 INF> (main) 
(org.apache.catalina.core.AprLifecycleListener#lifecycleEvent) APR 
capabilities: IPv6 [true], sendfile [true], accept filters [false], random 
[true], UDS [true].
19:39:09.263 INF> (main) 
(org.apache.catalina.core.AprLifecycleListener#lifecycleEvent) APR/OpenSSL 
configuration: useAprConnector [false], useOpenSSL [true]
19:39:09.274 INF> (main) 
(org.apache.catalina.core.AprLifecycleListener#initializeSSL) OpenSSL 
successfully initialized [OpenSSL 3.0.14 4 Jun 2024]

-Harri
________________________________
Lähettäjä: Harri Pesonen <harri.peso...@sinch.com>
Lähetetty: keskiviikko 21. toukokuuta 2025 12.37
Vastaanottaja: users@tomcat.apache.org <users@tomcat.apache.org>
Aihe: WebSocket session is never closed

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

Reply via email to