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

TypeError with HTTP Client #49909

Closed
NKozhuharov opened this issue Jan 30, 2024 · 6 comments · Fixed by #49924
Closed

TypeError with HTTP Client #49909

NKozhuharov opened this issue Jan 30, 2024 · 6 comments · Fixed by #49924
Labels

Comments

@NKozhuharov
Copy link

NKozhuharov commented Jan 30, 2024

Laravel Version

10.42.0

PHP Version

8.3

Database Driver & Version

No response

Description

Looks like a similar issue existed before - #37596.

Relevant stack trace:

TypeError: Illuminate\Http\Client\Events\ConnectionFailed::__construct(): Argument #1 ($request) must be of type Illuminate\Http\Client\Request, null given, called in /code/vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php on line 1424
#67 /vendor/laravel/framework/src/Illuminate/Http/Client/Events/ConnectionFailed.php(22): Illuminate\Http\Client\Events\ConnectionFailed::__construct
#66 /vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php(1424): Illuminate\Http\Client\PendingRequest::dispatchConnectionFailedEvent
#65 /vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php(924): Illuminate\Http\Client\PendingRequest::Illuminate\Http\Client\{closure}
#64 /vendor/laravel/framework/src/Illuminate/Support/helpers.php(248): retry
#63 /vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php(892): Illuminate\Http\Client\PendingRequest::send
#62 /vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php(770): Illuminate\Http\Client\PendingRequest::get

Steps To Reproduce

It happens sometimes, when calling

public function get(string $endpoint, array $query = [], int $tries = 3, int $timeout = 60): Response {
    $headers = [
        'X-Shopify-Access-Token' => 'my-token',
        'Content-Type'           => 'application/json',
    ];
    $response = Http::setClient(Http::buildClient())->withHeaders($headers)->timeout(60)->get($this->url($endpoint, $query));
}
@driesvints driesvints changed the title TypeError Illuminate\Http\Client\Events\ConnectionFailed::__construct(): Argument #1 ($request) must be of type Illuminate\Http\Client\Request, null given, called in /code/vendor/laravel/framework/src/Illuminate/Http/Client/PendingRequest.php on line 1424 TypeError with HTTP Client Jan 30, 2024
@driesvints
Copy link
Member

Can you provide a full reproducible example with endpoint and query?

@NKozhuharov
Copy link
Author

$endpoint = 'https://waterdrop-nl.myshopify.com/admin/api/2023-10/products/42859018911930/variants.json';
$query = []; //no query

This is the last logged url, but it happens sometimes, so I can't guarantee that this URL will reproduce it. Since ConnectionFailed is involved, I guess the server didn't respond at that moment.

@driesvints
Copy link
Member

How are you executing this? Within a CLI command? Or through a web request? Could you provide a complete step by step guide at what you're doing?

@NKozhuharov
Copy link
Author

The service is deployed and running in the Google Cloud Platform.

A scheduled task, that is running every 5 minutes is creating jobs in the Google Cloud Tasks. We're using the stackkit/laravel-google-cloud-tasks-queue to create the jobs in Cloud Tasks. Then GCP is calling the handle-task route to execute the task.

We're logging any errors via Sentry, there are 4 of this type today.

@driesvints
Copy link
Member

Thanks, I was suspecting this was through a non-web request. I can see an issue here where there's no request object bound yet to the PendingRequest but there's already a connection exception being thrown. Since the connection exception will always have a PSR request object attached, we can simply recreate the request object before sending the event. I've sent in a PR here: #49924

@NKozhuharov
Copy link
Author

Perfect, thank you! 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants