I'm trying to understand the difference between:
setRequestTimeout
- Set the maximum time in millisecond an AsyncHttpClient waits until the response is completed.
setReadTimeout
- Set the maximum time in millisecond an AsyncHttpClient can stay idle.
When should I use one versus the other?
And how do they relate to a good old java.net.SocketTimeoutException: Read timed out
?
The connection timeout is the timeout in making the initial connection; i.e. completing the TCP connection handshake. The read timeout is the timeout on waiting to read data1.
Overview. AsyncHttpClient (AHC) is a library build on top of Netty, with the purpose of easily executing HTTP requests and processing responses asynchronously. In this article, we'll present how to configure and use the HTTP client, how to execute a request and process the response using AHC.
From the client side, the “read timed out” error happens if the server is taking longer to respond and send information. This could be due to a slow internet connection, or the host could be offline. From the server side, it happens when the server takes a long time to read data compared to the preset timeout.
connection timeout — a time period in which a client should establish a connection with a server. socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.
Request timeout = maximum duration for completing a request from the user's perspective. It can account for the time to resolve the hostname, to open the TCP connection, to perform TLS handshake, to write the request and receive the complete response.
Read timeout = maximum time between consecutive reads. Typically used to crash when a large download is no longer making any progress.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With