You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2012/07/12 22:11:31 UTC
svn commit: r1360905 -
/tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Author: fhanik
Date: Thu Jul 12 20:11:31 2012
New Revision: 1360905
URL: http://svn.apache.org/viewvc?rev=1360905&view=rev
Log:
Correct handling of timeout - negative or zero means no timeout but an instant
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java?rev=1360905&r1=1360904&r2=1360905&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java Thu Jul 12 20:11:31 2012
@@ -196,7 +196,11 @@ public class NioSelectorPool {
//register OP_WRITE to the selector
if (key==null) key = socket.getIOChannel().register(selector, SelectionKey.OP_WRITE);
else key.interestOps(SelectionKey.OP_WRITE);
- keycount = selector.select(writeTimeout);
+ if (writeTimeout<=0) {
+ keycount = selector.selectNow();
+ } else {
+ keycount = selector.select(writeTimeout);
+ }
}
if (writeTimeout > 0 && (selector == null || keycount == 0) ) timedout = (System.currentTimeMillis()-time)>=writeTimeout;
}//while
@@ -264,7 +268,11 @@ public class NioSelectorPool {
//register OP_WRITE to the selector
if (key==null) key = socket.getIOChannel().register(selector, SelectionKey.OP_READ);
else key.interestOps(SelectionKey.OP_READ);
- keycount = selector.select(readTimeout);
+ if (readTimeout<=0) {
+ keycount = selector.selectNow();
+ } else {
+ keycount = selector.select(readTimeout);
+ }
}
if (readTimeout > 0 && (selector == null || keycount == 0) ) timedout = (System.currentTimeMillis()-time)>=readTimeout;
}//while
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1360905 - /tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Posted by Mark Thomas <ma...@apache.org>.
On 12/07/2012 21:42, Filip Hanik (mailing lists) wrote:
> You are correct, I was chasing down the following:
>
> Testsuite: org.apache.catalina.websocket.TestWebSocket
> Tests run: 6, Failures: 1, Errors: 0, Time elapsed: 2.048 sec
> ....
> INFO: Starting ProtocolHandler ["http-nio-127.0.0.1-auto-2-9027"]
> Jul 12, 2012 11:56:27 AM org.apache.coyote.AbstractProtocol$AbstractConnectionHandler process
> SEVERE: null
> java.lang.IllegalArgumentException: Negative timeout
> at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
> at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:267)
> at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:227)
> at org.apache.coyote.http11.upgrade.UpgradeNioProcessor.readSocket(UpgradeNioProcessor.java:139)
> at org.apache.coyote.http11.upgrade.UpgradeNioProcessor.read(UpgradeNioProcessor.java:112)
> 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:117)
> at org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(UpgradeProcessor.java:83)
> at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:583)
> at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
> at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1676)
> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
>
> We should not use -1 in our unit tests. I'm tempted to get rid of the -1 notion all together, no sane person should ever use no timeout :)
I do remember that the interpretation of -1 varied across the connectors
and I spent some time going through them making the handing consistent.
Looks like I missed a case there. Sorry.
There was a requirement for infinite timeouts from multiple WebSockets
users so I think they'll have to stay (much as I'd like to get rid of them).
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
RE: svn commit: r1360905 - /tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Posted by "Filip Hanik (mailing lists)" <de...@hanik.com>.
You are correct, I was chasing down the following:
Testsuite: org.apache.catalina.websocket.TestWebSocket
Tests run: 6, Failures: 1, Errors: 0, Time elapsed: 2.048 sec
....
INFO: Starting ProtocolHandler ["http-nio-127.0.0.1-auto-2-9027"]
Jul 12, 2012 11:56:27 AM org.apache.coyote.AbstractProtocol$AbstractConnectionHandler process
SEVERE: null
java.lang.IllegalArgumentException: Negative timeout
at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:97)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:267)
at org.apache.tomcat.util.net.NioSelectorPool.read(NioSelectorPool.java:227)
at org.apache.coyote.http11.upgrade.UpgradeNioProcessor.readSocket(UpgradeNioProcessor.java:139)
at org.apache.coyote.http11.upgrade.UpgradeNioProcessor.read(UpgradeNioProcessor.java:112)
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:117)
at org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(UpgradeProcessor.java:83)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:583)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1676)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
We should not use -1 in our unit tests. I'm tempted to get rid of the -1 notion all together, no sane person should ever use no timeout :)
> -----Original Message-----
> From: Mark Thomas [mailto:markt@apache.org]
> Sent: Thursday, July 12, 2012 2:20 PM
> To: Tomcat Developers List
> Subject: Re: svn commit: r1360905 -
> /tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
>
> On 12/07/2012 21:11, fhanik@apache.org wrote:
> > Author: fhanik
> > Date: Thu Jul 12 20:11:31 2012
> > New Revision: 1360905
> >
> > URL: http://svn.apache.org/viewvc?rev=1360905&view=rev
> > Log:
> > Correct handling of timeout - negative or zero means no timeout but an
> instant
>
> Nope. The expected and documented behaviour for a negative timeout for
> all connectors is an infinite timeout.
>
> Mark
>
> >
> >
> > Modified:
> > tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
> >
> > Modified:
> tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
> > URL:
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/ne
> t/NioSelectorPool.java?rev=1360905&r1=1360904&r2=1360905&view=diff
> >
> ========================================================================
> ======
> > --- tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
> (original)
> > +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
> Thu Jul 12 20:11:31 2012
> > @@ -196,7 +196,11 @@ public class NioSelectorPool {
> > //register OP_WRITE to the selector
> > if (key==null) key =
> socket.getIOChannel().register(selector, SelectionKey.OP_WRITE);
> > else key.interestOps(SelectionKey.OP_WRITE);
> > - keycount = selector.select(writeTimeout);
> > + if (writeTimeout<=0) {
> > + keycount = selector.selectNow();
> > + } else {
> > + keycount = selector.select(writeTimeout);
> > + }
> > }
> > if (writeTimeout > 0 && (selector == null || keycount
> == 0) ) timedout = (System.currentTimeMillis()-time)>=writeTimeout;
> > }//while
> > @@ -264,7 +268,11 @@ public class NioSelectorPool {
> > //register OP_WRITE to the selector
> > if (key==null) key =
> socket.getIOChannel().register(selector, SelectionKey.OP_READ);
> > else key.interestOps(SelectionKey.OP_READ);
> > - keycount = selector.select(readTimeout);
> > + if (readTimeout<=0) {
> > + keycount = selector.selectNow();
> > + } else {
> > + keycount = selector.select(readTimeout);
> > + }
> > }
> > if (readTimeout > 0 && (selector == null || keycount
> == 0) ) timedout = (System.currentTimeMillis()-time)>=readTimeout;
> > }//while
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: dev-help@tomcat.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1360905 - /tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
Posted by Mark Thomas <ma...@apache.org>.
On 12/07/2012 21:11, fhanik@apache.org wrote:
> Author: fhanik
> Date: Thu Jul 12 20:11:31 2012
> New Revision: 1360905
>
> URL: http://svn.apache.org/viewvc?rev=1360905&view=rev
> Log:
> Correct handling of timeout - negative or zero means no timeout but an instant
Nope. The expected and documented behaviour for a negative timeout for
all connectors is an infinite timeout.
Mark
>
>
> Modified:
> tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
>
> Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java
> URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java?rev=1360905&r1=1360904&r2=1360905&view=diff
> ==============================================================================
> --- tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java (original)
> +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioSelectorPool.java Thu Jul 12 20:11:31 2012
> @@ -196,7 +196,11 @@ public class NioSelectorPool {
> //register OP_WRITE to the selector
> if (key==null) key = socket.getIOChannel().register(selector, SelectionKey.OP_WRITE);
> else key.interestOps(SelectionKey.OP_WRITE);
> - keycount = selector.select(writeTimeout);
> + if (writeTimeout<=0) {
> + keycount = selector.selectNow();
> + } else {
> + keycount = selector.select(writeTimeout);
> + }
> }
> if (writeTimeout > 0 && (selector == null || keycount == 0) ) timedout = (System.currentTimeMillis()-time)>=writeTimeout;
> }//while
> @@ -264,7 +268,11 @@ public class NioSelectorPool {
> //register OP_WRITE to the selector
> if (key==null) key = socket.getIOChannel().register(selector, SelectionKey.OP_READ);
> else key.interestOps(SelectionKey.OP_READ);
> - keycount = selector.select(readTimeout);
> + if (readTimeout<=0) {
> + keycount = selector.selectNow();
> + } else {
> + keycount = selector.select(readTimeout);
> + }
> }
> if (readTimeout > 0 && (selector == null || keycount == 0) ) timedout = (System.currentTimeMillis()-time)>=readTimeout;
> }//while
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org