You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by William Leung <lw...@21cn.com> on 2007/10/08 09:07:44 UTC

soTimeout not worked on channelNioSocket

I have configuared tomcat to use the NIO impl over AJP, here are the lines in
server.xml
    <Connector address="127.0.0.1" port="0"

               channelNioSocket.port="8009"
               channelNioSocket.soTimeout="600000"
               channelNioSocket.bufferSize="16384"
               channelNioSocket.maxThreads="125"
               channelNioSocket.minSpareThreads="10"
               channelNioSocket.maxSpareThreads="50"

               redirectPort="8443" protocol="AJP/1.3"
               useBodyEncodingForURI="true"
               />

(TC version 5.5.17)
I had setted the soTimeout with 10 minutes, cause I notice such stages in
server status

Stage Time B Sent B Recv Client VHost Request 
S 33280840 ms 359 KB 0 KB x.x.x.x 127.0.0.1 GET ...

That shows several requests were blocking on reading request bodies for
hours.

But unfortunately it dosen't worked for me, I am expecting a request should
only blocking mostly 10 minutes on read, after that a SocketTimeoutException
should raised.

After digest the source code of ChannelNioSocket.java, I found that
ChannelNioSocket.SocketInputStream just wait infinitly if no data comes
while socket could not be detected closing

        private void block(int len) throws IOException {
            ... ...
            if(!dataAvailable) {
                blocking = true;
                if(log.isDebugEnabled())
                    log.debug("Waiting for "+len+" bytes to be available");
                try{
                    wait(socketTimeout);
                }catch(InterruptedException iex) {
                    log.debug("Interrupted",iex);
                }
                blocking = false;
            }
            if(dataAvailable) {
                dataAvailable = false;
                if(fill(len) < 0) {
                    isClosed = true;
                } 
            }
        }

The socketTimeout parameter is not used to throw SocketTimeoutException,
actually it has no meaning.

I even read the source for TC 6.0.13, the same as above.

Should it be more precisely that throwing SocketTimeoutException on later
condiction test for (dataAvailable) is not true?

In ChannelSocket implement, the problem is not exists,  it uses blocking
Socket.getInputStream, and it would throws SocketTimeoutException for socket
timeout while Socket.setSoTimeout was called
-- 
View this message in context: http://www.nabble.com/soTimeout-not-worked-on-channelNioSocket-tf4586318.html#a13091613
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: soTimeout not worked on channelNioSocket

Posted by William Leung <lw...@21cn.com>.
Thanks for reply.
It seems that neither the NIO impl nor the standard impl of AJP Connector do
not handle the case where Apache drops the connection in mid-request well.
I had try the standard way first, and still notice some requests blocks for
hours (socket timeout is not setted).
As busy threads count was so high, but most of them were just keepalive, so
I decided to try NIO.
(I didnt try APR yet)



Bill Barker-2 wrote:
> 
> More generally, it looks like it isn't handling the case where Apache
> drops 
> the connection in mid-request well :(.  Oh, well, there is a reason that
> the 
> NIO impl over AJP is "experimental" (and thus not documented).
> 
> Yes, it should probably throw an exception when the wait() returns without 
> any data available, but it also needs work to handle the case where Apache 
> drops the connection.  As Filip suggested on the dev list, open up a BZ 
> issue for this, and if you want to try your hand at adding a patch, it
> will 
> be much appreciated :).  Otherwise, I'll look into producing a patch
> myself.
> 
> And many thanks for testing this :).
> 
> "William Leung" <lw...@21cn.com> wrote in message 
> news:13091613.post@talk.nabble.com...
>>
>> I have configuared tomcat to use the NIO impl over AJP, here are the
>> lines 
>> in
>> server.xml
>>    <Connector address="127.0.0.1" port="0"
>>
>>               channelNioSocket.port="8009"
>>               channelNioSocket.soTimeout="600000"
>>               channelNioSocket.bufferSize="16384"
>>               channelNioSocket.maxThreads="125"
>>               channelNioSocket.minSpareThreads="10"
>>               channelNioSocket.maxSpareThreads="50"
>>
>>               redirectPort="8443" protocol="AJP/1.3"
>>               useBodyEncodingForURI="true"
>>               />
>>
>> (TC version 5.5.17)
>> I had setted the soTimeout with 10 minutes, cause I notice such stages in
>> server status
>>
>> Stage Time B Sent B Recv Client VHost Request
>> S 33280840 ms 359 KB 0 KB x.x.x.x 127.0.0.1 GET ...
>>
>> That shows several requests were blocking on reading request bodies for
>> hours.
>>
>> But unfortunately it dosen't worked for me, I am expecting a request 
>> should
>> only blocking mostly 10 minutes on read, after that a 
>> SocketTimeoutException
>> should raised.
>>
>> After digest the source code of ChannelNioSocket.java, I found that
>> ChannelNioSocket.SocketInputStream just wait infinitly if no data comes
>> while socket could not be detected closing
>>
>>        private void block(int len) throws IOException {
>>            ... ...
>>            if(!dataAvailable) {
>>                blocking = true;
>>                if(log.isDebugEnabled())
>>                    log.debug("Waiting for "+len+" bytes to be
>> available");
>>                try{
>>                    wait(socketTimeout);
>>                }catch(InterruptedException iex) {
>>                    log.debug("Interrupted",iex);
>>                }
>>                blocking = false;
>>            }
>>            if(dataAvailable) {
>>                dataAvailable = false;
>>                if(fill(len) < 0) {
>>                    isClosed = true;
>>                }
>>            }
>>        }
>>
>> The socketTimeout parameter is not used to throw SocketTimeoutException,
>> actually it has no meaning.
>>
>> I even read the source for TC 6.0.13, the same as above.
>>
>> Should it be more precisely that throwing SocketTimeoutException on later
>> condiction test for (dataAvailable) is not true?
>>
>> In ChannelSocket implement, the problem is not exists,  it uses blocking
>> Socket.getInputStream, and it would throws SocketTimeoutException for 
>> socket
>> timeout while Socket.setSoTimeout was called
>> -- 
>> View this message in context: 
>> http://www.nabble.com/soTimeout-not-worked-on-channelNioSocket-tf4586318.html#a13091613
>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/soTimeout-not-worked-on-channelNioSocket-tf4586318.html#a13109778
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: soTimeout not worked on channelNioSocket

Posted by Bill Barker <wb...@wilshire.com>.
More generally, it looks like it isn't handling the case where Apache drops 
the connection in mid-request well :(.  Oh, well, there is a reason that the 
NIO impl over AJP is "experimental" (and thus not documented).

Yes, it should probably throw an exception when the wait() returns without 
any data available, but it also needs work to handle the case where Apache 
drops the connection.  As Filip suggested on the dev list, open up a BZ 
issue for this, and if you want to try your hand at adding a patch, it will 
be much appreciated :).  Otherwise, I'll look into producing a patch myself.

And many thanks for testing this :).

"William Leung" <lw...@21cn.com> wrote in message 
news:13091613.post@talk.nabble.com...
>
> I have configuared tomcat to use the NIO impl over AJP, here are the lines 
> in
> server.xml
>    <Connector address="127.0.0.1" port="0"
>
>               channelNioSocket.port="8009"
>               channelNioSocket.soTimeout="600000"
>               channelNioSocket.bufferSize="16384"
>               channelNioSocket.maxThreads="125"
>               channelNioSocket.minSpareThreads="10"
>               channelNioSocket.maxSpareThreads="50"
>
>               redirectPort="8443" protocol="AJP/1.3"
>               useBodyEncodingForURI="true"
>               />
>
> (TC version 5.5.17)
> I had setted the soTimeout with 10 minutes, cause I notice such stages in
> server status
>
> Stage Time B Sent B Recv Client VHost Request
> S 33280840 ms 359 KB 0 KB x.x.x.x 127.0.0.1 GET ...
>
> That shows several requests were blocking on reading request bodies for
> hours.
>
> But unfortunately it dosen't worked for me, I am expecting a request 
> should
> only blocking mostly 10 minutes on read, after that a 
> SocketTimeoutException
> should raised.
>
> After digest the source code of ChannelNioSocket.java, I found that
> ChannelNioSocket.SocketInputStream just wait infinitly if no data comes
> while socket could not be detected closing
>
>        private void block(int len) throws IOException {
>            ... ...
>            if(!dataAvailable) {
>                blocking = true;
>                if(log.isDebugEnabled())
>                    log.debug("Waiting for "+len+" bytes to be available");
>                try{
>                    wait(socketTimeout);
>                }catch(InterruptedException iex) {
>                    log.debug("Interrupted",iex);
>                }
>                blocking = false;
>            }
>            if(dataAvailable) {
>                dataAvailable = false;
>                if(fill(len) < 0) {
>                    isClosed = true;
>                }
>            }
>        }
>
> The socketTimeout parameter is not used to throw SocketTimeoutException,
> actually it has no meaning.
>
> I even read the source for TC 6.0.13, the same as above.
>
> Should it be more precisely that throwing SocketTimeoutException on later
> condiction test for (dataAvailable) is not true?
>
> In ChannelSocket implement, the problem is not exists,  it uses blocking
> Socket.getInputStream, and it would throws SocketTimeoutException for 
> socket
> timeout while Socket.setSoTimeout was called
> -- 
> View this message in context: 
> http://www.nabble.com/soTimeout-not-worked-on-channelNioSocket-tf4586318.html#a13091613
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org