Skip to content

Commit 11eaeb7

Browse files
[Fix] CommonHttpsClient Builder - set timeout correctly (#362)
## 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]>
1 parent aa066bb commit 11eaeb7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

databricks-sdk-java/src/main/java/com/databricks/sdk/core/commons/CommonsHttpClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ public CommonsHttpClient build() {
104104

105105
private static final Logger LOG = LoggerFactory.getLogger(CommonsHttpClient.class);
106106
private final CloseableHttpClient hc;
107-
private int timeout;
108107

109108
private CommonsHttpClient(Builder builder) {
110-
HttpClientBuilder httpClientBuilder =
111-
HttpClientBuilder.create().setDefaultRequestConfig(makeRequestConfig());
112109
int timeoutSeconds = 300;
113110
if (builder.databricksConfig != null
114111
&& builder.databricksConfig.getHttpTimeoutSeconds() != null) {
@@ -117,7 +114,9 @@ private CommonsHttpClient(Builder builder) {
117114
if (builder.timeoutSeconds != null) {
118115
timeoutSeconds = builder.timeoutSeconds;
119116
}
120-
timeout = timeoutSeconds * 1000;
117+
int timeout = timeoutSeconds * 1000;
118+
HttpClientBuilder httpClientBuilder =
119+
HttpClientBuilder.create().setDefaultRequestConfig(makeRequestConfig(timeout));
121120
if (builder.proxyConfig != null) {
122121
ProxyUtils.setupProxy(builder.proxyConfig, httpClientBuilder);
123122
}
@@ -135,7 +134,7 @@ private CommonsHttpClient(Builder builder) {
135134
hc = httpClientBuilder.build();
136135
}
137136

138-
private RequestConfig makeRequestConfig() {
137+
private RequestConfig makeRequestConfig(int timeout) {
139138
return RequestConfig.custom()
140139
.setConnectionRequestTimeout(timeout)
141140
.setConnectTimeout(timeout)

0 commit comments

Comments
 (0)