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

Asssociate timeout to underlying Jetty HTTP client #24007

Closed
wants to merge 6 commits into from
Closed

Asssociate timeout to underlying Jetty HTTP client #24007

wants to merge 6 commits into from

Conversation

Kukosoft
Copy link

@Kukosoft Kukosoft commented Nov 15, 2019

The websocket handshake timeout is now the sum of connection timeout, idle tiemout and 1 margin second.

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;
		};
Connection timeout is now associated to Jetty client timeout plus 50ms extra padding.
Timeout must consider also the idle timeout  of the Jetty client
Change idle Jetty max idle timeout for underlying HTTP Client
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 15, 2019
@rstoyanchev
Copy link
Contributor

The timeout part has already been done (see the commit that closed #23994). As for cancelling the future, as far as I can see in Jetty's WebSocketUpgradeRequest the CompletableFuture is only notified on completion/erro and never checked for cancellation. I don't think the cancellation would make any difference.

@rstoyanchev rstoyanchev added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 18, 2019
@Kukosoft
Copy link
Author

Ok, Rossen. One note about the current timeout implementation. I think that this.client.getHttpClient().getIdleTimeout() must be added to HTTP client connect timeout because the websocket upgrade can take also the request "read time"

@rstoyanchev
Copy link
Contributor

rstoyanchev commented Nov 19, 2019

@Kukosoft, I agree handshake time isn't quite the same as the connect time, but idleTimeout is a completely different property altogether that's not a good fit for connecting. How long you might be willing to leave the connection idle isn't necessarily how long you want to wait to connect. Also it doesn't have any default value that we can use.

If you goal is to have configurable control, you already can change connectTimeout to anything and that gives enough control for this case I think. Just set it to however long you're willing to wait altogether.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants