socket_helper: set SO_KEEPALIVE on TCP sockets
commitee6ffca0a8d129dd930f4c63d0c4c9ef034b245f
authorEric Wong <normalperson@yhbt.net>
Mon, 5 Dec 2011 01:33:41 +0000 (5 01:33 +0000)
committerEric Wong <normalperson@yhbt.net>
Mon, 5 Dec 2011 01:33:41 +0000 (5 01:33 +0000)
tree39440e39247f194198ea12ddf4318c5d449cb4c2
parent27f666a973a59c8c6738a65b69f9060c41e6958c
socket_helper: set SO_KEEPALIVE on TCP sockets

Even LANs can break or be unreliable sometimes and socket
disconnect messages get lost, which means we fall back to
the global (kill -9) timeout in Unicorn.

While the default global timeout is much shorter (60s) than
typical TCP timeouts, some HTTP application dispatches take much
I/O or computational time (streaming many gigabytes), so the
global timeout becomes ineffective.

Under Linux, sysadmins are encouraged to lower the default
net.ipv4.tcp_keepalive_* knobs in sysctl.  There should be
similar knobs in other operating systems (the default keepalive
intervals are usually ridiculously high, too high for anything).

When the listen socket has SO_KEEPALIVE set, the flag should be
inherited by accept()-ed sockets.
lib/unicorn/socket_helper.rb