Skip to content

Commit

Permalink
[java] Setting a connection timeout for the WS connection
Browse files Browse the repository at this point in the history
Fixes #13884
  • Loading branch information
diemol committed Apr 30, 2024
1 parent 9c8133a commit 2f7ac69
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ public class JdkHttpClient implements HttpClient {
private final List<WebSocket> websockets;
private final ExecutorService executorService;
private final Duration readTimeout;
private final Duration connectTimeout;

JdkHttpClient(ClientConfig config) {
Objects.requireNonNull(config, "Client config must be set");

this.messages = new JdkHttpMessages(config);
this.readTimeout = config.readTimeout();
this.connectTimeout = config.connectionTimeout();
this.websockets = new ArrayList<>();
this.handler = config.filter().andFinally(this::execute0);

Expand All @@ -98,7 +100,7 @@ public class JdkHttpClient implements HttpClient {

java.net.http.HttpClient.Builder builder =
java.net.http.HttpClient.newBuilder()
.connectTimeout(config.connectionTimeout())
.connectTimeout(connectTimeout)
.followRedirects(java.net.http.HttpClient.Redirect.NEVER)
.executor(executorService);

Expand Down Expand Up @@ -165,6 +167,7 @@ public WebSocket openSocket(HttpRequest request, WebSocket.Listener listener) {
CompletableFuture<java.net.http.WebSocket> webSocketCompletableFuture =
client
.newWebSocketBuilder()
.connectTimeout(connectTimeout)
.buildAsync(
uri,
new java.net.http.WebSocket.Listener() {
Expand Down

0 comments on commit 2f7ac69

Please sign in to comment.