how long to keep sockets in the state FIN-WAIT-2

$cat /proc/sys/net/ipv4/tcp_fin_timeout

The tcp_fin_timeout variable tells kernel how long to keep sockets in the state FIN-WAIT-2 if you were the one closing the socket. This is used if the other peer is broken for some reason and don’t close its side, or the other peer may even crash unexpectedly. Each socket left in memory takes approximately 1.5Kb of memory, and hence this may eat a lot of memory if you have a moderate webserver or something alike.

This value takes an integer value which is per default set to 60 seconds. This used to be 180 seconds in 2.2 kernels, but was reduced due to the problems mentioned above with webservers and problems that arose from getting huge amounts of connections.
Copyright © 2002 by Oskar Andreasson Under GNU FDL

Connection is closed, and the socket is waiting for a shutdown from the remote end.
    55:                                   * close the socket, about 60 seconds  */
    56: #define TCP_FIN_TIMEOUT (3*60*HZ) /* BSD style FIN_WAIT2 deadlock breaker */
    57: #define TCP_ACK_TIME    (3*HZ)  /* time to delay before sending an ACK  */ - GPL - C -