-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
excluded_http_codes
not working as intended for http errors thrown inside the callback of a StreamedResponse
#57902
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
Comments
Wasn't this fixed by #51396 |
Let’s close here meanwhile. We can reopen if it turns out that it wasn’t fixed by the linked PR. |
@nicolas-grekas Sorry for the delay, here's a repo that reproduces the issue: https://github.com/mathieuimbert/symfony-streamed-response-issue. |
Thanks for the reproducer, this will be fixed by #58289 |
@nicolas-grekas Indeed, thank you 🥳 Let me know if I can help with your PR. |
…dler`, assume `$kernel->terminateWithException()` will do it (nicolas-grekas) This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Skip logging uncaught exceptions in `ErrorHandler`, assume `$kernel->terminateWithException()` will do it | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57902 | License | MIT When uncaught exceptions are handled by `ErrorHandler::handleException()`, that method logs them, then calls a callback to let the app know about the exception itself. This causes two issues: 1. that log happens without context, which leads to #57902 2. logs are duplicated: one by ErrorHandler, twice by the callback In this PR, I propose to consider that if terminateWithException is configured as a callback, we assume that the app will handle the logging on its own. Tested in practice, this works nicely. Adding a test case is quite complex as all this involves many pieces and global state, so I skipped adding one. Commits ------- 3b87c32 [HttpKernel] Skip logging uncaught exceptions in ErrorHandler, assume $kernel->terminateWithException() will do it
Symfony version(s) affected
6.4.10
Description
6.4.10
3.7.0
I stumbled on this issue after upgrading from Symfony 5 to 6. When a HttpException is thrown inside the callback of a StreamedResponse, it is ignored by
excluded_http_codes
and logged anyway.This happens because
$this->requestStack->getMainRequest()
returnsnull
in https://github.com/symfony/symfony/blob/6.4/src/Symfony/Bridge/Monolog/Handler/FingersCrossed/HttpCodeActivationStrategy.php#L53This is a consequence of the
stack->pop()
done in https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/HttpKernel/HttpKernel.php#L103 as soon as the callback ran.How to reproduce
fingers_crossed
monolog handler withexcluded_http_codes
Go to
/home
and notice that the 404 error is loggedMove
throw new NotFoundHttpException('This is a test exception');
before thesetCallback()
function and notice that the 404 error is not logged (as expected)Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: