So_keepalive option for outbound sockets

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

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 D.
http://nginx.org/

Hi,

Thanks for your prompt reply.

On Fri, Jul 22, 2016 at 7:32 AM, Maxim D. [email protected]
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 D.
http://nginx.org/


nginx mailing list
[email protected]
nginx Info Page

Aditya