Why does `setConnectionRequestTimeout` not stop my request for 1 minute?

I have this code:

    RequestConfig requestConfig = RequestConfig.custom()
            .setConnectTimeout(40 * 1000)
            .setConnectionRequestTimeout(40 * 1000)
            .setSocketTimeout(40 * 1000)
            .build();
    client = HttpClientBuilder
            .create()
            .setDefaultRequestConfig(requestConfig)
            .build();
}

and

    try {

        Stopwatch stopWatch = Stopwatch.createStarted();
        response = client.execute(new HttpGet(routingRequestUrl));
        stopWatch.stop();

    } catch (Exception e) {
        answer.errorMsg = e.getMessage();
        answer.latency =  null;
    }

when my client configuration does not contain .setSocketTimeout(40 * 1000)- showWatch request may take more than 1 minute.

This happens when I try to execute setConnectTimeoutand setConnectionRequestTimeouteach separately or all together.

Why only .setSocketTimeout(40 * 1000)effectively checks for a timeout of 40 seconds? and the other is not?

These are the fingerprints:

Read timed out

Timeout waiting for connection from pool

The first is called setConnectionRequestTimeout, and the second is setSocketTimeout?

+4
source share
1 answer

https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/client/config/RequestConfig.html

getConnectionRequestTimeout()

Returns the timeout in milliseconds used when requesting a connection from the connection manager.

getConnectTimeout()

- , .

getSocketTimeout()

- (SO_TIMEOUT) , - , -, ).

__

, , connectionRequestTimeout , , , .

connectTimeout . , tcp.

socketTimeout, , - . , .

+15

Source: https://habr.com/ru/post/1599522/


All Articles