How to activate TCP Keepalive?


I am using Gatling (3.0.3) and I am facing a NAT gateway idle connection timeout on slow requests (~6min).
Gatling continues to wait forever for the response while the connection is dropped between the gateway and the target server.

Unfortunately, I cannot change this timeout, it is an AWS NAT Gateway with a hardcoded 350s timeout.

A classic solution to bypass a NAT router idle timeout is to use TCP keepalive.

This requires to change the OS (linux) configuration on the Gatling host to have some keepalive activity before the timeout (changing tcp_keepalive_time from 7200 to 60):

net.ipv4.tcp_keepalive_intvl = 60
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_time = 60

But so far it does not work: the problem remains.
Looking at the Gatling connection I cannot see any keepalive activity with tcpdump nor netstat (the Timer column displays keepalive when active):

$ netstat -latopen
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name Timer
tcp 0 0 X.X.X.X:80 ESTABLISHED 1001 1201186 18767/java off (0.00/0/0)

Am I missing something or Gatling/Netty does not use the SO_KEEPALIVE option by default?

Thanks for your help and keep up the good work.


FYI, I will try to add a ChannelOption.SO_KEEPALIVE option to the DefaultHttpClient,

if it fixes my problem I will provide a PR.


Yes, that should fix it.
A PR would be much appreciated!
Please please make it configurable just like other socket options (disabled by default, just like Linux default).


It looks like it is working, the connection is now listed with a nice keepalive:

tcp 0 0 XX.XXX.XX.XXX:80 ESTABLISHED 1001 7875653 28067/java keepalive (205.37/0/0)

I have created:
and done a first PR: