caseyamcl / guzzle_retry_middleware

Middleware for Guzzle v6/7+ that automatically retries HTTP requests on 429, 503 responses.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'retry_on_timeout': false blocks all ConnectException not only timeout

ViktorCollin opened this issue · comments

Detailed description

First of all I want to thank you for a great project!

When have set the retry_on_timeout setting to false (default value) it blocks all request resulting in a ConnectException from being retried. This causes confusion when using the library. I have some suggested solutions of varying degree ROI. I can help with the implementation if you want to, just let me know what solution you prefer.

Context

protected function shouldRetryConnectException(array $options, RequestInterface $request): bool
{
    return $options['retry_enabled']
        && ($options['retry_on_timeout'] ?? false)
        && $this->hasTimeAvailable($options) !== false
        && $this->countRemainingRetries($options) > 0
        && $this->ensureMethod($options, $request);
}

https://github.com/caseyamcl/guzzle_retry_middleware/blob/v2.9.0/src/GuzzleRetryMiddleware.php#L230-L243

Possible implementation

  1. Just rename retry_on_timeout to retry_on_connection_issue
    Pros: Small amount of work
    Cons: Require a major version bump which may be a bit aggressive for such a small change
  2. Introduce a new option called retry_on_connection_issue with a default value of false and deprecating the retry_on_timeout option. Check if ether one is true when deciding if a retry should be done
    Pros: Keep backwards compatibility
    Cons: Require the documentation to be clear in order to avoid confusion

There are more possible solutions, please let me know what you think