Socket keepalive property

Viewed 94

We use okhttp3 lib with spring boot on service side.

OktHttp is configured to use connection pool.

We have found that okhttp does not enable keepalive for socket. Do you know a reason why?

Our linux machine is configured with

net.ipv4.tcp_keepalive_time=60
net.ipv4.tcp_keepalive_intvl=6
net.ipv4.tcp_keepalive_probes=10

And we expect that all tcp connections will inherit these settings.

But if you check connection state with netstat -town you will see that keepalive is not enabled.

It can be an issue for cases when your border controller (firewall, gateway) drops idle connections

I can solve this issue with custom SocketFactory like this

@Override
public Socket createSocket() throws IOException {
    var socket = socketFactory.createSocket();
    socket.setKeepAlive(true);
    return socket;
}

but maybe I miss something

Thanks,

0 Answers
Related