I have an HTTP server implemented with Netty. It takes long-poll connections for pushing messages to the browsers. In most of the times, the server won’t try to close the connection.
In a TCP session, if any side wants to close the connection, it sends a FIN packet to the other. What if the server doesn’t receive FIN from the client, in the cases such as 1) the user has hard network failures or 2) someone tries to attack the server, is it guaranteed that the Netty server will receive a timeout (or other kind of) exception after a given time?
If it’s true, I don’t need to add a Read/WriteTimeoutHandler into my channel pipeline which closes the channel when the Timer triggers timeout. I have to close the channel in either way, otherwise I will leak resources.
No. There is a
SocketTimeoutExceptionthat is thrown if the socket is in blocking mode and a read timeout has been set. There is anIOException: connection resetwhich can happen if TCP keepalive has been enabled and the connection really stays broken for 2 hours: this does not include the case where the peer is merely silent with the connection remaining operative. Otherwise no.