so_keepalive option for outbound sockets
adityaumrani at gmail.com
Fri Jul 22 16:54:59 UTC 2016
Thanks for your prompt reply.
On Fri, Jul 22, 2016 at 7:32 AM, Maxim Dounin <mdounin at mdounin.ru> wrote:
> On Thu, Jul 21, 2016 at 07:02:48PM -0700, Aditya Umrani wrote:
>> I've configured the so_keepalive option for a server (this is also my
>> default server). I do have other server configs listening to the same
>> listen 9822 default_server so_keepalive=on;
>> listen 29822 ssl http2 default_server so_keepalive=on;
>> My sysctl settings are set to :
>> net.ipv4.tcp_keepalive_time = 120
>> net.ipv4.tcp_keepalive_probes = 10
>> net.ipv4.tcp_keepalive_intvl = 120
>> However, I see that no tcp keepalive packets are being sent on
>> outbound connections (from nginx to the upstream). I also checked the
>> output of 'netstat -an --timers' I see that no outbound sockets have
>> the 'keepalive' flag. All of them are 'off'. If it matters, the server
>> config which actually servers this request is not the default one, but
>> one of the other configs.
>> I took a quick look at the code and the 'SO_KEEPALIVE' options only
>> shows up on functions which deal with listening sockets. Does this
>> mean that nginx does not honor this option for outbound connections?
> Yes. The so_keepalive parameter is configured on listening
> sockets and applies to connections accepted though these sockets.
> Using SO_KEEPALIVE on sockets to backends are not generally
> needed, as these connections are usually local and
> well-controlled. (And if it's not the case, many operation
> systems have an option to request TCP keepalive for all
> connection, like net.inet.tcp.always_keepalive on FreeBSD.
> Though looks like Linux isn't able to do so.)
I will give it a shot through some LD_PRELOAD tricks. Let me know if
anyone has other suggestions.
> Maxim Dounin
> nginx mailing list
> nginx at nginx.org
More information about the nginx