Project: Tomcat
Bug 55200 [websocket] Problem writing many subsequent binary messages
Reported: 2013-07-05 14:27:48 | Status: resolved fixed

I see sometimes failing connections due to IOException (see below). This happens when trying to send thousands of binary messages (1024 bytes each) without any delay between the subsequent messages. Having look at the code in AsyncChannelWrapperSecure$WriteTask.run(219), I think it is not correct to assume that if not all of the bytes in the buffer are written, this shall produce IOException. I think in this case, there shall be an attempt to write the rest of the bytes in a cycle. Here one exception I got during the test: Exception is :java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: Only wrote [460] of [1,098] bytes at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:204) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendBytes(WsRemoteEndpointImplBase.java:113) at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendBinary(WsRemoteEndpointBasic.java:43) at WebsocketsTestManager$TestThread.run(WebsocketsTestManager.java:271) Caused by: java.util.concurrent.ExecutionException: java.io.IOException: Only wrote [460] of [1,098] bytes at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$FutureToSendHandler.get(WsRemoteEndpointImplBase.java:729) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessageBlock(WsRemoteEndpointImplBase.java:202) ... 3 more Caused by: java.io.IOException: Only wrote [460] of [1,098] bytes at org.apache.tomcat.websocket.AsyncChannelWrapperSecure$WriteTask.run(AsyncChannelWrapperSecure.java:220) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:789)

Files changed in fix:
java/org/apache/tomcat/websocket/AsyncChannelWrapperSecure.java