[PLUG] Closing sockets using atexit C code.

John Meissen john at meissen.org
Tue Nov 14 22:43:25 UTC 2017


larry.brigman at gmail.com said:
> TCP Connections will linger in the kernel for about 15 minutes after the
> application closes them.  Those can be seen from netstat or ss as TIME_WAIT.

> A user/process has limits on file descriptors.  A non-root user by default is
> only allowed 1024. 

Actually, it's related to ports, not filehandles. If one program crashes it's 
not going to affect other processes' filehandles.

The connection lingers, and ties up the port that it was associated with. You 
typically see this with restarting servers, when they want to bind to a 
specific port it's still in use from the previous process. But you can also run 
into problems if you have one of more processes making outgoing connections 
rapidly - it's possible to run out of available ports for the local side of the  
connection to use. Normally you'd almost never see this, but if you had a 
process that was continually crashing and restarting it could happen.

You can mitigate it by using SO_REUSEADDR, which is what server processes 
usually do.







More information about the PLUG mailing list