Skip to content

Fix default connectTimeout of transportBuilder #1633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

playLeo
Copy link
Contributor

@playLeo playLeo commented Jun 19, 2025

Description

ConnectionConfig connectTimeout is used only when the connectTimeout in RequestConfig is null.
However, the builder is currently setting a value for connectTimeout in RequestConfig, which causes the value in ConnectionConfig to be ignored.

Therefore, it is safe to remove the default setting in RequestConfig.
Also, ConnectionConfig already defines a default value:
Timeout DEFAULT_CONNECT_TIMEOUT = Timeout.ofMinutes(3)

Issues Resolved

This PR is related to #1581

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Leo added 2 commits June 19, 2025 13:00
Signed-off-by: Leo <yggb159@gmail.com>
Signed-off-by: Leo <yggb159@gmail.com>
@playLeo playLeo changed the title Fix default connetTimeOut of transportBuilder Fix default connectTimeout of transportBuilder Jun 19, 2025
Signed-off-by: Leo <yggb159@gmail.com>
@@ -328,7 +328,6 @@ public static ApacheHttpClient5TransportBuilder builder(HttpHost... hosts) {
private CloseableHttpAsyncClient createHttpClient() {
// default timeouts are all infinite
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(DEFAULT_CONNECT_TIMEOUT_MILLIS))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s remove DEFAULT_CONNECT_TIMEOUT_MILLIS from this class since we don’t need it here now.

@001mertiya
Copy link
Contributor

@reta Why is there a discrepancy in the default connect timeout? The default value is 1 second in ApacheHttpClient5TransportBuilder, but it’s 3 minutes by default in ConnectionConfig.

@reta
Copy link
Collaborator

reta commented Jun 20, 2025

@reta Why is there a discrepancy in the default connect timeout? The default value is 1 second in ApacheHttpClient5TransportBuilder, but it’s 3 minutes by default in ConnectionConfig.

@001mertiya This timeout setting was carried over from https://github.com/opensearch-project/OpenSearch/blob/main/client/rest/src/main/java/org/opensearch/client/RestClientBuilder.java#L71

Signed-off-by: Leo <yggb159@gmail.com>

PoolingAsyncClientConnectionManager connectionManager = PoolingAsyncClientConnectionManagerBuilder
.create()
.setDefaultConnectionConfig(connectionConfig)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@001mertiya could you clarify please what exactly you are trying to achieve here? The RequestConfig and ConnectionConfig are different configuration settings. If you are not satisfied with the RequestConfigsettings, use requestConfigCallback to set them to any value, including null

Copy link
Contributor Author

@playLeo playLeo Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reta
The connectTimeout setting has been moved from RequestConfig to ConnectionConfig, and since the setting in RequestConfig has been deprecated, I think it should be removed. Also, the purpose of this test was to verify that the connectTimeout works correctly when a connection is established using the ConnectionConfig setting.

Copy link
Collaborator

@reta reta Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @playLeo , if it was deprecated and is not working anymore, we should make sure our API does switch to ConnectionConfig from RequestConfig

Copy link
Contributor Author

@playLeo playLeo Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here http5client commit link!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, my point is: we have class RequestConfigCallback [1] that historically was used to configure timeouts in question. Now, since has timeout related methods deprecated, we could (and probably should) reflect that by introducing ConnectionConfigCallback to allow configuring these timeouts.

[1] https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/transport/httpclient5/ApacheHttpClient5TransportBuilder.java#L376

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed explanation. I understand. I have a question before I start working. It seems that you can configure RequestConfig and ConnectionConfig either by using HttpClientConfigCallback or by using RequestConfigCallback and ConnectionConfigCallback. Doesn’t having both ways to set these configurations create potential confusion? What is the benefit of using ConnectionConfigCallback?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @playLeo , since the timeout properties from RequestConfig have been moved (and potentially removed), the ConnectionConfig is the way to configure those (we would need to document that).

Copy link
Contributor Author

@playLeo playLeo Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could (and probably should) reflect that by introducing ConnectionConfigCallback to allow configuring these timeouts.

I think I did not explain it clearly. If we create a ConnectionConfigCallback we would then have two ways to set the ConnectionConfig one through the existing HttpClientConfigCallback and one through the new ConnectionConfigCallback so I am wondering if the ConnectionConfigCallback is really necessary.

I also know that for RequestConfig there are two ways to configure it using HttpClientConfigCallback and RequestConfigCallback but I am wondering if the RequestConfigCallback is really needed in that case too.

If there are two ways to configure this, wouldn’t that be confusing? Are you saying it’s fine as long as it’s documented properly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are two ways to configure this, wouldn’t that be confusing? Are you saying it’s fine as long as it’s documented properly?

Yeah, so the ConnectionConfigCallback is only useful when the caller does not want to deal with connection manager (since it is part of it). In this case, providing just ConnectionConfigCallback and not HttpClientConfigCallback would work just fine. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the updated

@playLeo playLeo force-pushed the fix/connectTimeout branch from 5b8654e to 26a3872 Compare July 4, 2025 03:09
Signed-off-by: Leo <yggb159@gmail.com>
@playLeo playLeo force-pushed the fix/connectTimeout branch from 26a3872 to aff280f Compare July 4, 2025 03:09
@001mertiya
Copy link
Contributor

Hi @playLeo, can you pull the latest changes from main and add these test on top of that? There was an issue with socketTimeout as well, fixed in the latest main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants