mrkkrp / req

An HTTP client library
Other
337 stars 40 forks source link

Set a retrying limit by default for request timeouts #114

Closed poscat0x04 closed 3 years ago

poscat0x04 commented 3 years ago

Currently, under the default setting req will retry forever if the exception thrown by http-client is a ResponseTimeout or a ConnectionTimeout. This can potentially lead the program to block indefinitely under the circumstances where throwing an exception is more desirable, say, for example, when the network is down or the server you are requesting to is down. I feel like there should be a default retrying limit.

mrkkrp commented 3 years ago

You seem to be confused by the definition of httpConfigRetryJudgeException. This function only tells us when to retry. The number of retries and the time intervals between them are set in the httpConfigRetryPolicy: https://github.com/mrkkrp/req/blob/master/Network/HTTP/Req.hs#L536-L540. By default, we use retryPolicyDefault: https://github.com/mrkkrp/req/blob/master/Network/HTTP/Req.hs#L746, which says:

The default retry policy retryPolicyDefault implements a constant 50ms delay, up to 5 times

http://hackage.haskell.org/package/retry-0.8.1.2/docs/Control-Retry.html#t:RetryPolicyM

poscat0x04 commented 3 years ago

Yeah, you're right. Sorry. I guess I should read the code more carefully.