I think I understand the formal meaning of the option. In some legacy code I'm handling now, the option is used. The customer complains about RST as response to FIN from its side on connection close from its side.
I am not sure I can remove it safely, since I don't understand when it should be used.
Can you please give an example of when the option would be required?
The typical reason to set a
SO_LINGERtimeout of zero is to avoid large numbers of connections sitting in theTIME_WAITstate, tying up all the available resources on a server.When a TCP connection is closed cleanly, the end that initiated the close ("active close") ends up with the connection sitting in
TIME_WAITfor 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.This isn't a good idea, though -
TIME_WAITexists for a reason (to ensure that stray packets from old connections don't interfere with new connections). It's a better idea to redesign your protocol to one where the client initiates the connection close, if possible.