question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebClient HTTP Request Timeout

See original GitHub issue

I’d like for WebClient and/or ClientRequest to have first-class support for an HTTP request timeout. (i.e. the time it takes to receive a response after sending a request). Something similar to the java http client’s request timeout.

The currently documented use of netty’s ReadTimeoutHandler / WriteTimeoutHandler is insufficient to use as an HTTP request timeout. Specifically they apply at the TCP level, which leads to problems like this:

  1. They apply during the SSL handshake, which might take longer than a typical HTTP response, due to the cryptography involved. Therefore, they would need to be set higher than desired for HTTP responses.
  2. They apply even when an HTTP request is not being processed. For example, they could cause a connection sitting in the connection pool to be closed, even though it might be able to be used a split-second later by another request.

The .timeout operator on the reactive stream is insufficient to use as an HTTP request timeout as well. Specifically, it operates on the reactive stream, which includes things like obtaining a connection from the connection pool and potentially creating a new connection, in addition to the time it takes the client to receive a response. This leads to having to use a .timeout value this is greater than the connection timeout plus the time to obtain the connection from the connection pool. So, the .timeout operator cannot be used as an HTTP request timeout. I’m willing to “pay the price” of establishing connections occasionally (leading to waiting longer occasionally for the stream to emit), but I’d still like to set a lower HTTP request timeout, to ensure the stream emits values fast when a new connection is not established.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rstoyanchevcommented, Aug 24, 2020

I’ve exposed this on WebClient so you could do:

WebClient.create()
	.get().uri("/path")
	.httpRequest(httpRequest -> {
		HttpClientRequest clientRequest = httpRequest.getNativeRequest();
		clientRequest.responseTimeout(Duration.ofSeconds(5));
	})
	.retrieve()
	...
1reaction
rstoyanchevcommented, Aug 21, 2020

Yes that’s the idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set a Timeout in Spring 5 Webflux WebClient - Baeldung
Learn how to configure timeout settings for our WebClient using Spring ... To perform HTTP requests, we can use the WebClient interface, ...
Read more >
Setting Timeout with Spring WebClient - HowToDoInJava
Learn to set connection timeout, read timeout and write timeout periods for ... available in Spring 5 for making asynchronous HTTP requests.
Read more >
Configure timeout for Spring WebFlux WebClient - amitph
The Response Timeout defines the maximum time a client, after sending a request, waits to receive the response. With WebClient, we can set...
Read more >
How to change the timeout on a .NET WebClient object
I'd recommend first performing a HEAD HTTP request and examining the Content-Length header value returned to determine the number of bytes in the...
Read more >
Configuring timeouts in Spring reactive WebClient
A typical request to downstream reactive endpoint using WebClient would look like below. webClient.get() .uri(uri) .retrieve() .onStatus(HttpStatus::isError, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found