On 04/10/2013 22:49, Konstantin Preißer wrote:
> Hi Mark,
> 
> while I was developing and experimenting with a WebSocket application (that I 
> think could be added to Tomcat 8's WebSocket examples), I think I found some 
> more possible issues with the Websocket handling. One of these can be seen 
> with the Snake example.
> 
> 
> A) For NIO and APR connector:
> It seems that when a client establishes a Websocket connection and then stops 
> to read data from it (but doesn't close the connection, so that writing data 
> to the underlying TCP connection will be blocked), and then after some time 
> continues to read data from the Websocket connection, then Tomcat seems not 
> to be able to read data from that client any more (and doesn't notice when 
> the connection has been closed), but it can still read from it.

I think you have written read when you meant write somewhere in the
previous sentence.

> To reproduce:
> 1) Start Tomcat (current trunk) on Windows 64-bit with Java7 64-bit and 
> either NIO or APR connector.
> 2) Open two instances of Firefox (that may or may not be on the same machine) 
> and open the snake example. On both instances, press up or down key so that 
> both snakes begin moving.
> 3) Suspend one of the two Firefox processes (say Firefox B). This can be done 
> with "Process Explorer" [1] tool by right-clicking on the firefox.exe entry 
> and select "Suspend". You can see that Firefox B does not respond any more, 
> but on Firefox A the snakes continue to move.
> 4) After some time, you can see that on Firefox A the snakes suddenly stop 
> moving. This is correct because the current code uses RemoteEndpoint.Basic 
> that may block on write() methods.
> 5) Now resume Firefox B with Process Explorer. You can see that on both 
> Firefoxes the snakes will continue to move. This means that both Firefoxes 
> are able to receive data from the Websocket connection.
> 6) When you try to change the direction of the snake in Firefox A, everything 
> works. However on Firefox B, the snake will not change its direction. This 
> means that while Tomcat continues to send data to this Websocket connection, 
> it cannot receive from it any more.
> 7) If you close Firefox B, then the corresponding snake will not disappear 
> (so it seems Tomcat doesn't notice that the connection closed).

It would be worth taking a look with something like Wireshark to see if
the data is being sent to Tomcat.

> B) For BIO connector:
> I noticed that on Tomcat with BIO connector, when using a 
> RemoteEndpoint.Async to asynchronously send data over the WebSocket 
> connection, sendText(String, SendHandler) (or similar methods) will block if 
> the Remote endpoint does not read data from the connection, whereas for NIO 
> and APR connector this method will always return immediately.
> Is it intended that for the BIO connector those methods are blocking? As the 
> javadoc says, "Initiates the asynchronous transmission of a text message. 
> This method returns before the message is transmitted.", I would have 
> expected that e.g. another Thread is used to write in blocking mode, so that 
> the sendText() method can return immediately.

You can't do non-blocking IO with the BIO connector. All communication
with BIO is blocking. This is working as designed.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to