Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Prevent crash when handling ConnectionException in HttpClient retry logic #50955

Merged
merged 2 commits into from
Apr 8, 2024
Merged

Conversation

shinsenter
Copy link
Contributor

Recently, I have been using HttpClient to crawl some websites in order to extract data for personal purposes. During the crawler monitoring process, I noticed that many errors like the following appear:

  Error 
  Call to undefined method Illuminate\Http\Client\ConnectionException::toException()

  at vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php:1058
    1054▕             return $exception;
    1055▕         }
    1056▕ 
    1057▕         if ($attempt < $this->tries && $shouldRetry) {
  ➜ 1058▕             $options['delay'] = value($this->retryDelay, $attempt, $response->toException());
    1059▕ 
    1060▕             return $this->makePromise($method, $url, $options, $attempt + 1);
    1061▕         }
    1062▕ 

      +14 vendor frames 

After reading through the source code at the error location, I found that when the $response variable is of type ConnectionException, an error occurs at line 1058 because there is no toException() method defined in the ConnectionException class.

$options['delay'] = value($this->retryDelay, $attempt, $response->toException());

This pull request will add a condition to check the data type of the $response variable before passing it as a parameter to the value() function. This approach is similar to other locations within the same handlePromiseResponse() function where the value is being used, so I think it will not affect other functionalities.

I would appreciate if you could review and merge this patch.

This commit fixes this error:
```
Call to undefined method Illuminate\Http\Client\ConnectionException::toException()
```
@driesvints
Copy link
Member

Heya! We were having some failures in the testsuite at the base branch. Could you rebase this PR, make sure tests pass and mark for review again? Thanks!

@driesvints driesvints marked this pull request as draft April 8, 2024 10:07
@shinsenter shinsenter marked this pull request as ready for review April 8, 2024 13:21
@taylorotwell taylorotwell merged commit 4c26433 into laravel:11.x Apr 8, 2024
28 checks passed
@shinsenter shinsenter deleted the patch-1 branch April 8, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants