You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Steffen Heil (Mailinglisten)" <li...@steffen-heil.de> on 2015/08/25 18:12:37 UTC

Connection resets without timeout

Hi


When using async servlets with timeout set to 0, tomcat seems not to detect, if the client closes the connection.
At least the servlet listener is not notified.

I expected "AsyncListener.onComplete" or "AsyncListener.onError" or "AsyncListener.onTimeout", but none of these are called.
The only thing called is "ReadListener.onAllDataRead" but that’s expected as the request is a POST request with few inbound data but long running outbound data.

Now we have no way to detect when the connection to the client is broken.
On TCP level the connection was closed (FIN/FIN+ACK), so tomcat should know that the connection is gone.
Is there any way to get notified about that or at least to check manually?


Regards,
  Steffen



BTW: I am posting new questions that are not direct follow-ups as top messages. If there is another policy for this list, please let me know.


AW: Connection resets without timeout

Posted by "Steffen Heil (Mailinglisten)" <li...@steffen-heil.de>.
Hi


For everyone following this thread, here are some conclusions I came up with.

First I need to correct myself: I saw FIN/ACK, not FIN/FIN+ACK (at least I could not reproduce that).
So when the client program gets closed, the tcp stack of the client sends FIN and the server running tomcat replies with FIN+ACK.
What I did not realize earlier is, that this does NOT close the tcp connection at all. It isn't even supposed to.
Because TCP offers no way to reliably close a connection.

Instead it simply tells the server that the client will not send any more payload data. So the connection is "half-closed".
But by definition the server may still send data to the client [2]. And the client has no way to prevent that [1].

So tomcat known that there will be no additional data, but it is absolutely valid to send more.
As the connection cannot be "closed" there is no way to detect that the client application is gone.

As soon as tomcat sends something, the client tcp stack recognized incoming packets that do not match an open connection and therefor sends RST.
At that point of the connection is completely gone and tomcat does report that to the servlet (using onError, as writing failed).


While I did a lot in the area of networking and even implemented my own NIO stack, I must confess I never realized that tcp connections cannot be closed by one side.


Regards,
  Steffen


[1] This is not strictly true, as the client might send RST instead of FIN, but that could lead to packet loss for data send before the RST.

[2] If you think about HTTP/1.0 you see how that can be useful. In a POST/PUT request the client payload is send to the server. The server needs to detect the end of that payload. That can be done using "Content-Length"-Header or chunked encodinig ("0" terminator) or by closing the connection (inbound only) after the data. However, even if the inbound connection is closed, the response should still be sent to the client, so in that case the client even expects some answer after he sent FIN...


> -----Ursprüngliche Nachricht-----
> Von: Steffen Heil (Mailinglisten) [mailto:lists@steffen-heil.de]
> Gesendet: Dienstag, 25. August 2015 18:13
> An: Tomcat Users List <us...@tomcat.apache.org>
> Betreff: Connection resets without timeout
> 
> Hi
> 
> 
> When using async servlets with timeout set to 0, tomcat seems not to detect, if the client closes the connection.
> At least the servlet listener is not notified.
> 
> I expected "AsyncListener.onComplete" or "AsyncListener.onError" or "AsyncListener.onTimeout", but none of these are called.
> The only thing called is "ReadListener.onAllDataRead" but that’s expected as the request is a POST request with few inbound data but
> long running outbound data.
> 
> Now we have no way to detect when the connection to the client is broken.
> On TCP level the connection was closed (FIN/FIN+ACK), so tomcat should know that the connection is gone.
> Is there any way to get notified about that or at least to check manually?
> 
> 
> Regards,
>   Steffen
> 
> 
> 
> BTW: I am posting new questions that are not direct follow-ups as top messages. If there is another policy for this list, please let me
> know.


Re: Connection resets without timeout

Posted by Mark Thomas <ma...@apache.org>.
On 25/08/2015 17:34, Gregory Gerard wrote:
> I'm curious as well -- I ran into this too and the only work around I had was to send a heartbeat which, if the client was gone, would complete the lifecycle (server sent events in my particular case).
> 
> This was ugly and felt wrong so I'd love to know the right thing to do.

Test with 8.0.26 and if you still see the issue open a bug report. We
have fixed something similar for WebSocket previously. [1]

Mark

[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=57762


> 
>> On Aug 25, 2015, at 12:12, Steffen Heil (Mailinglisten) <li...@steffen-heil.de> wrote:
>>
>> Hi
>>
>>
>> When using async servlets with timeout set to 0, tomcat seems not to detect, if the client closes the connection.
>> At least the servlet listener is not notified.
>>
>> I expected "AsyncListener.onComplete" or "AsyncListener.onError" or "AsyncListener.onTimeout", but none of these are called.
>> The only thing called is "ReadListener.onAllDataRead" but that’s expected as the request is a POST request with few inbound data but long running outbound data.
>>
>> Now we have no way to detect when the connection to the client is broken.
>> On TCP level the connection was closed (FIN/FIN+ACK), so tomcat should know that the connection is gone.
>> Is there any way to get notified about that or at least to check manually?
>>
>>
>> Regards,
>>  Steffen
>>
>>
>>
>> BTW: I am posting new questions that are not direct follow-ups as top messages. If there is another policy for this list, please let me know.
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


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


Re: Connection resets without timeout

Posted by Gregory Gerard <gg...@gmail.com>.
I'm curious as well -- I ran into this too and the only work around I had was to send a heartbeat which, if the client was gone, would complete the lifecycle (server sent events in my particular case).

This was ugly and felt wrong so I'd love to know the right thing to do.

> On Aug 25, 2015, at 12:12, Steffen Heil (Mailinglisten) <li...@steffen-heil.de> wrote:
> 
> Hi
> 
> 
> When using async servlets with timeout set to 0, tomcat seems not to detect, if the client closes the connection.
> At least the servlet listener is not notified.
> 
> I expected "AsyncListener.onComplete" or "AsyncListener.onError" or "AsyncListener.onTimeout", but none of these are called.
> The only thing called is "ReadListener.onAllDataRead" but that’s expected as the request is a POST request with few inbound data but long running outbound data.
> 
> Now we have no way to detect when the connection to the client is broken.
> On TCP level the connection was closed (FIN/FIN+ACK), so tomcat should know that the connection is gone.
> Is there any way to get notified about that or at least to check manually?
> 
> 
> Regards,
>  Steffen
> 
> 
> 
> BTW: I am posting new questions that are not direct follow-ups as top messages. If there is another policy for this list, please let me know.
> 

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