Skip to content

Commit

Permalink
[Fix] CommonHttpsClient Builder - set timeout correctly (#362)
Browse files Browse the repository at this point in the history
## Changes
The issue was that `makeRequestConfig` was using `timeout` before it was
initialized, I have refactored the code to both fix and make it more
error proof in the future

## Tests
Not possible to write UT for this as its too encapsulated, will need
major refactors to be able to test via UT

Co-authored-by: hectorcast-db <[email protected]>
  • Loading branch information
satviksr-db and hectorcast-db authored Oct 18, 2024
1 parent aa066bb commit 11eaeb7
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,8 @@ public CommonsHttpClient build() {

private static final Logger LOG = LoggerFactory.getLogger(CommonsHttpClient.class);
private final CloseableHttpClient hc;
private int timeout;

private CommonsHttpClient(Builder builder) {
HttpClientBuilder httpClientBuilder =
HttpClientBuilder.create().setDefaultRequestConfig(makeRequestConfig());
int timeoutSeconds = 300;
if (builder.databricksConfig != null
&& builder.databricksConfig.getHttpTimeoutSeconds() != null) {
Expand All @@ -117,7 +114,9 @@ private CommonsHttpClient(Builder builder) {
if (builder.timeoutSeconds != null) {
timeoutSeconds = builder.timeoutSeconds;
}
timeout = timeoutSeconds * 1000;
int timeout = timeoutSeconds * 1000;
HttpClientBuilder httpClientBuilder =
HttpClientBuilder.create().setDefaultRequestConfig(makeRequestConfig(timeout));
if (builder.proxyConfig != null) {
ProxyUtils.setupProxy(builder.proxyConfig, httpClientBuilder);
}
Expand All @@ -135,7 +134,7 @@ private CommonsHttpClient(Builder builder) {
hc = httpClientBuilder.build();
}

private RequestConfig makeRequestConfig() {
private RequestConfig makeRequestConfig(int timeout) {
return RequestConfig.custom()
.setConnectionRequestTimeout(timeout)
.setConnectTimeout(timeout)
Expand Down

0 comments on commit 11eaeb7

Please sign in to comment.