'Apache ClosableHTTPAsyncClient socketTimeout not enforced

I'm running into a few sporadic Connection Reset By Peer. On examining the tcpdump, I see that stale connections are probably being reused which makes the service I'm invoking return a RST segment.

RequestConfig requestConfig =
        RequestConfig.copy(RequestConfig.DEFAULT)
            .setConnectionRequestTimeout(10 * 1000)
            .setConnectTimeout(30 * 1000)
            .setSocketTimeout(30 * 1000)
            .build();

    PoolingNHttpClientConnectionManager connManager =
        new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor());
    connManager.setDefaultMaxPerRoute(30);
    connManager.setMaxTotal(100);

    HttpAsyncClientBuilder builder =
        HttpAsyncClientBuilder.create()
            .setDefaultRequestConfig(requestConfig)
            .setConnectionManager(connManager);

httpAsyncClient = builder.build();
httpAsyncClient.start();

The above httpAsyncClient is later reused to make HTTP requests to the service.

TCP Dump for the following (truncated)

00:53:53.069570 IP sourceIP.43378 > destIP.https: Flags [.], ack 50724, win 443, options [nop,nop,TS val 3252050405 ecr 3146302244], length 0
00:53:53.161925 IP sourceIP.43378 > destIP.https: Flags [P.], seq 19754:20246, ack 50724, win 443, options [nop,nop,TS val 3252050497 ecr 3146302244], length 492
00:53:53.170401 IP destIP.https > sourceIP.43378: Flags [.], ack 20246, win 559, options [nop,nop,TS val 3146302344 ecr 3252050497], length 0
00:53:53.183885 IP destIP.https > sourceIP.43378: Flags [P.], seq 50724:52040, ack 20246, win 559, options [nop,nop,TS val 3146302358 ecr 3252050497], length 1316
00:53:53.183903 IP sourceIP.43378 > destIP.https: Flags [.], ack 52040, win 443, options [nop,nop,TS val 3252050519 ecr 3146302358], length 0
(notice the next timestamp is several minutes later compared to the previous packet)
01:00:41.723977 IP sourceIP.43378 > destIP.https: Flags [P.], seq 20246:20738, ack 52040, win 443, options [nop,nop,TS val 3252459059 ecr 3146302358], length 492
01:00:41.725326 IP destIP.https > sourceIP.43378: Flags [R.], seq 52040, ack 20738, win 443, length 0

I was under the impression that if the socket was unused for more than 30 seconds, it should be closed by the client? If not, what would be a way for me to close stale connections?

The behaviour that is being observed however is that, the client still continues to reuse the stale connection which results in a RST from the server.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source