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:li...@steffen-heil.de]
> Gesendet: Dienstag, 25. August 2015 18:13
> An: Tomcat Users List <users@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.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to