There are updates to this page that haven't been applied because you've entered text. Refresh this page to see updates.
Hide this message.

Answer Stats

Robert's AnswerView Question
Robert LoveRobert Love, I hack on Linux & worked on An... (more)
6 upvotes by Jay Kreps, Ben Maurer, Jude Paul, (more)
In the default case, upon
close
()
the network stack attempts to gracefully shutdown the connection after ensuring all data is sent but this occurs asynchronouslyin the backgroundand the call to
close
()
will return without guaranteeing that this shutdown has completed.


The
SO_LINGER
case is, of course, different. It has two modes of operation: When
l_linger
is zero and when it is nonzero. When zero,
close
()
still returns immediately, but unsent data is discarded and (for connection-oriented protocols) the connection is reset (e.g., a RST is sent in the case of TCP). When nonzero, the
close
()
behaves synchronously and blocks until the time specified by
l_linger
elapses, at which point the behavior is as in the zero
l_linger
case.

I can see plenty of design choices that would suggest you should or should not use
SO_LINGER
, but if that behavior is desirable for your application I would not classify them as "downsides."