Closed brandensam26 closed 3 years ago
Well, the first thing I would ask is to upgrade. if you still have the mashape namespace, that version is super old and has some issues.
@ryber thanks for the suggestion. I've already upgraded unirest to the latest version.
But, is there a way to set/control the read timeout in unirest?
Just a note: I'm using the unirest along with springboot 2.3
It depends on what you mean by "read timeout". There is no limit in unirest for total read time, you could spend hours downloading some gigantic file, and as long as bytes are moving you're ok. The SocketTimeoutException
is thrown when you exceed the timout for a single socket read. So in your case, manipulating the socket timeout is the right thing to play with. I would say that taking 10 seconds for a single socket read is pretty bad and may be an indication of network instability.
@ryber Thank you so much for your valuable inputs. In my case, the socket read time can take up to 15 seconds. So wanted to increase the read timeout. I've upgraded Unirest to the latest version and the app is now under testing. I'll also check if there is any network instability in my environment.
@brandensam26 was this issue resolved for you?
Why is ifFailure not triggered in case of a SocketTimeoutException?
ifFailure gets called in the case of a HTTP failure or a failure to parse the results into the desired body, you will note that it accepts a HttpResponse<T>
, in the case of a SocketTimeoutException there is no HttpResponse. Now we could provide a dummy response, but it would not have any status code or anything. This is actually done in the async client, I'll look into doing something similar but it might be confusing for users.
Oh wait, I remember, so you can change this behavior, it does this because it has always done this and changing it at this point is a breaking change. BUT, if you provide a Interceptor and override onFail there, its default behavior is to throw but you can change it to return a FailedResponse
. I might make that the default behavior but will probably wait until I have a few more breaking changes and do them all at once
So what is your suggested fix do deal with SocketTimeoutException meanwhile? Could you maybe provice a code example?
Hi,
Recently, I'm facing read timeouts issues in rest API calls.
I've observed that when it takes more than 10s to get the response it throws
Caused by: com.mashape.unirest.http.exceptions.UnirestException: java.net.SocketTimeoutException: Read timed out
I see that I can set connection timeout and socket timeout in Unirest. Increasing the connection and socket timeout did not solve this issue. Is there a way to increase the read timeout in Unirest?