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

[TraceableHttpClient] Timing issues with "fire & forget" requests #48326

Closed
cleptric opened this issue Nov 25, 2022 · 3 comments
Closed

[TraceableHttpClient] Timing issues with "fire & forget" requests #48326

cleptric opened this issue Nov 25, 2022 · 3 comments

Comments

@cleptric
Copy link

Symfony version(s) affected

v6.1.7

Description

While adding HTTP client tracing in the Sentry Symfony Bundle, I noticed an issue when tracing "fire & forget" requests.

As far as I can tell, there is no reliable way to determine if the request is completed without explicitly calling $response->getContent() or $response->toArray().

In this case, the StopwatchEvent will only be stopped during TraceableResponse::__destruct

How to reproduce

$response = $this->client->request('GET',
    'https://google.com'
);

Possible Solution

No response

Additional Context

getsentry/sentry-symfony#606 (comment)

@stof
Copy link
Member

stof commented Nov 25, 2022

If you intend to forget the request (without actually forgetting the Response object so it is not destructed yet), there is indeed no PHP code that will run at the exact time the last network packet is received. That's a direct consequence of the design of the HttpClient API meant to support concurrency.

@cleptric
Copy link
Author

cleptric commented Nov 25, 2022

Interesting, this is definitely a good observation.

$this->client->request('GET',
    'http://google.com'
);

Not assigning the response to a variable does indeed give me the correct timing.
I'll point this out in our docs.

Thanks!

@stof
Copy link
Member

stof commented Nov 25, 2022

Note however that doing 2 requests like that in your code will make them sequential and not concurrent (as the destructor forces waiting until the status code to enforce that failed requests are handled and the destructor is called immediately in such code)

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

No branches or pull requests

4 participants