views:

60

answers:

2

I think I understand the formal meaning of the option. In a legacy code I'm handling now, the option is used. The customer complains about RST as response to FIN from it's side on connection close from it's side.

I don't sure I can remove it safely, since don't understand when it should be used.

Can you please give an example when the option may be required.

+1  A: 

When linger is off the TCP stack doesn't wait for pending data to be sent before closing the connection. Data could be lost due to this but by setting linger to off you're accepting this and asking that the connection be reset straight away rather than closed gracefully. This causes an RST to be sent rather than the usual FIN.

Len Holgate
I understand this. what I'm asking is for "realistic" example when we would like to use hard reset.
dimba
Whenever you want to abort a connection; so if your protocol fails validation and you have a client talking rubbish at you all of a sudden you'd abort the connection with an RST, etc.
Len Holgate
+2  A: 

The typical reason to turn off SO_LINGER is to avoid large numbers of connections sitting in the TIME_WAIT state, tying up all the available resources on a server.

When a TCP connection is closely cleanly, the end that initiated the close ("active close") ends up with the connection sitting in TIME_WAIT for several minutes. So if your protocol is one where the server initiates the connection close, and involves very large numbers of short-lived connections, then it might be susceptible to this problem.

caf