Skip to content
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

Avoid indefinite wait to connect in JettyWebSocketClient #23994

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -22,6 +22,7 @@
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
Expand Down Expand Up @@ -155,7 +156,13 @@ public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler w

Callable<WebSocketSession> connectTask = () -> {
Future<Session> future = this.client.connect(listener, uri, request);
future.get();
try {
// TODO Configurable timeout
future.get(2000, TimeUnit.MILLISECONDS);
} catch (Exception ex){
logger.error("Failed to connect to remote websocket endpoint", ex);
future.cancel(true); // This method will stop the running underlying task
}
return wsSession;
};

Expand Down