Bug 53074 - [websocket] java.net.SocketTimeoutException: Read timed caused by server.xml' connectTimeout
[websocket] java.net.SocketTimeoutException: Read timed caused by server.xml'...
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
unspecified
PC Mac OS X 10.4
: P2 normal with 1 vote (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-04-13 13:45 UTC by Jean-Francois Arcand
Modified: 2012-06-13 16:07 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jean-Francois Arcand 2012-04-13 13:45:11 UTC
The default connectTimeout value is set to 20000 and cause issue with WebSocket connection

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at org.apache.coyote.http11.upgrade.UpgradeBioProcessor.read(UpgradeBioProcessor.java:75)
    at org.apache.catalina.websocket.WsFrame.nextFrame(WsFrame.java:213)
    at org.apache.catalina.websocket.WsInputStream.nextFrame(WsInputStream.java:68)
    at org.apache.catalina.websocket.StreamInbound.onData(StreamInbound.java:143)
    at org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(UpgradeProcessor.java:83)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:563)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)

Increasing the value delay the issue (but the timeout should not occurs)
Comment 1 Peter Rossbach 2012-04-14 12:31:18 UTC
Must we set the timeout to unlimited, or you thing it is better that client can overwrite it?
Comment 2 Jean-Francois Arcand 2012-04-14 13:16:16 UTC
Salut,

I think it should be unlimited, but an idle timeout setting would be useful (I do support idle timeout with Atmosphere, but I think Tomcat could support the same as well).

If you want to test using Atmosphere, download atmosphere-spring-websocket.war from search.maven.org (remove the -0.9 in the name) and deploy. After 20 seconds the app will stop working and Chrome will display a protocol exception. Ping me directly if that can help.

Thanks!

-- Jeanfrancois
Comment 3 Mark Thomas 2012-05-15 08:18:59 UTC
I've been thinking about this and I think the following is the way to go.

1. Make the connection timeout infinite.
2. Add an idle timeout to the WebSocket implementation (defaults to infinite) that times out if there is no input or output after a predefined amount of time. This should be configurable per connection.
3. Add a "ping every n milliseconds" feature (disabled by default) to save applications re-inventing the wheel.

Thoughts?

As an aside, 1) will be tricky with the APR/native connector. That needs some separate work. I'll start a thread on that on the dev list.
Comment 4 Jean-Francois Arcand 2012-05-15 14:12:59 UTC
Hi Mark,

+1 for making the connection timeout infinite. +1 also to add support for websocket timeout property/attribute (will be really useful). 

Not sure for the ping ... some applications don't need ping or that extra traffic on the wire. At least this should be configurable.

Thanks for the work.

-- Jeanfrancois
Comment 5 huck 2012-05-20 13:43:05 UTC
Hi,

+1 here for the option of configuring the timeout. My application requires an infinite connection which will be closed when required. I was negatively suprised to see tomcat has such a short timeout option.

please add an option to configure this at the very least.


meanwhile is there a workaround other than constant client reconnection?

thanks
Comment 6 Mark Thomas 2012-05-23 21:15:58 UTC
Just a short progress update.

I have committed a set of changes to the APR/native connector to permit per socket timeouts. It works with my simple tests but needs more testing and review by some proper C coders (which I am not).

I also have a first draft of the changes to trunk to enable infinite timeouts for WebSocket connections. That also needs some testing. I should have something to commit in the next couple of days.
Comment 7 Mark Thomas 2012-05-25 16:40:22 UTC
Fixed in trunk. Will be back-ported to 7.0.x once there has been a new release of the APR/native connector.
Comment 8 Jean-Francois Arcand 2012-05-25 16:45:25 UTC
Ok thanks! I will go ahead and test using trunk. Will report if I see any issues.
Comment 9 Mark Thomas 2012-06-13 16:07:40 UTC
Fixed in trunk and 7.0.x and will be included in 7.0.28 onwards.