opensearch-project / opensearch-project/opensearch-java
Connect timeout is not triggering as expected when set in ConnectionConfig
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 165
- Forks
- 250
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 26
Description
What is the bug?
The connect timeout in the ConnectionConfig is not working as expected.
How can one reproduce the bug?
Try creating the client by setting the connect timeout in ConnectionConfig as shown in the code snippet below, and use a very low value for the timeout (e.g., 1ms). Despite this, the connection does not fail as expected. However, if the connect timeout is set in RequestConfig, it works correctly.
ApacheHttpClient5TransportBuilder httpClientTransportBuilder = ApacheHttpClient5TransportBuilder.builder(hosts)
.setHttpClientConfigCallback(httpClientBuilder -> {
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
for (HttpHost host : hosts) {
credentialsProvider.setCredentials(new AuthScope(host),
new UsernamePasswordCredentials(openSearchClientConfigurations.getClusterUsername(), openSearchClientConfigurations.getClusterPassword().toCharArray()));
}
ConnectionConfig connectionConfig = ConnectionConfig.custom()
**.setConnectTimeout(Timeout.of(openSearchClientConfigurations.getConnectTimeout()))**
.setSocketTimeout(Timeout.of(openSearchClientConfigurations.getSocketTimeout()))
.setTimeToLive(TimeValue.of(openSearchClientConfigurations.getConnectionKeepAlive()))
.build();
PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
.create()
.setMaxConnPerRoute(openSearchClientConfigurations.getMaxConnectionPerRoute())
.setMaxConnTotal(openSearchClientConfigurations.getMaxConnectionTotal())
.setDefaultConnectionConfig(**connectionConfig**)
.build();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setConnectionManager(**connectionManager**);
})
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder .setConnectionRequestTimeout(Timeout.of(openSearchClientConfigurations.getConnectionRequestTimeout())))
}
return httpClientTransportBuilder;
What is the expected behavior?
The expected behavior is to throw a timeout exception when the specified connection timeout duration is exceeded.
Do you have any additional context?
Interestingly, setting the connect timeout in RequestConfig is deprecated, and it is now recommended to set it in ConnectionConfig. However, setting it in ConnectionConfig does not seem to work as expected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing ApacheHttpClient5TransportBuilder through the httpClientConfigCallback, ConnectionConfig, PoolingAsyncClientConnectionManager, and RequestConfig callback shown in the report. Reproduce the 1ms connect-timeout case and compare the ConnectionConfig and RequestConfig paths; done means the configured ConnectionConfig timeout causes the expected timeout exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100