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
Conversation
In some cases, org.eclipse.jetty.websocket.client.WebSocketClient.connect(listener, uri, request) call will return a future that never is completed. It is reasonable that our future.get() must have a timeout to avoid thread blocking. I suggest something like: Callable<WebSocketSession> connectTask = () -> { Future<Session> future = this.client.connect(listener, uri, request); 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; };
@Kukosoft Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@Kukosoft Thank you for signing the Contributor License Agreement! |
I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. |
A connect timeout is better set at the level of the underlying HttpClient. In this case, |
In practice, in a performance test I have set this connectTimeout to 500ms and I have few threads blocked in the get() method indefinitely...
I think we need to protect against any bug from third party libraries. |
Okay we could get the connectTimeout from the Jetty WebClient and wait for as long or a little longer. I don't think we should be exposing the same property for this though. It sounds like an issue that should be reported to Jetty because if the Jetty HttpClient keeps getting stuck, giving up on is also an issue. |
I'm totally agree with you. Jetty WebSocketClient is sometimes and somehow not completing its Future connection, so, Spring's side needs a protection like you said. |
If the |
In some cases,
org.eclipse.jetty.websocket.client.WebSocketClient.connect(listener, uri, request)
call will return a future that is never completed. It is reasonable that ourfuture.get()
must have a timeout to avoid thread blocking.I suggest something like: