Forum: NGINX so_keepalive option for outbound sockets

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
70bc1dd5807887f623d69c4e7da260a4?d=identicon&s=25 Aditya Umrani (Guest)
on 2016-07-22 04:03
(Received via mailing list)
Hello,

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
port.
========
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?

Thanks,
Aditya
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2016-07-22 16:33
(Received via mailing list)
Hello!

On Thu, Jul 21, 2016 at 07:02:48PM -0700, Aditya Umrani wrote:

> My sysctl settings are set to :
> 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.)

--
Maxim Dounin
http://nginx.org/
70bc1dd5807887f623d69c4e7da260a4?d=identicon&s=25 Aditya Umrani (Guest)
on 2016-07-22 18:55
(Received via mailing list)
Hi,

Thanks for your prompt reply.

On Fri, Jul 22, 2016 at 7:32 AM, Maxim Dounin <mdounin@mdounin.ru>
wrote:
>> listen 9822 default_server so_keepalive=on;
>> However, I see that no tcp keepalive packets are being sent on
> 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
> http://nginx.org/
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



Aditya
This topic is locked and can not be replied to.