Netty HttpClient - response timeout vs. read timeout

13.6k views Asked by At

HttpClient from offers various "timeouts" to be configured, two slightly confuses me:

  • responseTimeout: This is time that takes to receive a response after sending a request
  • ReadTimeoutHandler: Raises a ReadTimeoutException when no data was read within a certain period of time

Could someone please explain the key difference between them?


Generic scenario - make a call using spring reactive WebClient, that uses HttpClient under the hood:

  1. establish connection to remote server >>> here we leverage ChannelOption.CONNECT_TIMEOUT_MILLIS
  2. TLS handshake >>> here we leverage ReadTimeoutHandler as I am correct?
  3. Send request
  4. ...wait...
  5. Receive response >>> which "timeout" takes precedence here: response/read?
2

There are 2 answers

4
meberhard On

If you use WebFlux and Netty, the httpClient should be the Netty httpClient. Did you have a look there? https://projectreactor.io/docs/netty/release/api/reactor/netty/http/client/HttpClient.html

  1. Connect timeOut -> this is correct, if you can't connect to the remote server for any reason, this timeOut will be used.

  2. TLS handshake, check: reactor.netty.http.client.HttpClient#secure(): If not configured otherwise, Netty will assume 10 seconds timeout for the handshake. If you want to define another timeout, use reactor.netty.tcp.sslHandshakeTimeout https://projectreactor.io/docs/netty/release/api/reactor/netty/http/client/HttpClient.html#secure--

  3. The connection is now established and you send your request. By using ReadTimeoutHandler you can define how long to wait until you receive data over the connection. This could be for example the whole response in one go, or bytes if the responses is streamed. responseTimeout in httpClient does the same. Both create the TcpClient with the given timeOut setting. The benefit of ReadTimeoutHandler is that you get a callback that executes logic you defined when the timeout occurs.

0
asceta On

As suggested in comment from @violeta-georgieva > Netty HttpClient - response timeout vs. read timeout the "responseTimeout" should be used.