[3.0] Count the errors that are on the stack, not the errors that happened - #9606
Open
albertlast wants to merge 1 commit into
Open
[3.0] Count the errors that are on the stack, not the errors that happened#9606albertlast wants to merge 1 commit into
albertlast wants to merge 1 commit into
Conversation
The guard that stops error logging looping is a count of how deep the call is, and it was only cleared by reaching the end of the method. Returning early because logging is switched off skipped that, so the count kept climbing and the third error in a request died with a backtrace and 'loop detected' even though nothing had recursed. Balancing the count in a finally covers that return, and any error raised between the two, without depending on where the method ends up leaving. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
Collaborator
Author
|
in my opinion the bot change many code, dunno if we want this way? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ErrorHandlerService::log()keeps a count so that an error raised while logging an error does not go round for ever. The count is incremented on the way in and was cleared by reaching the end of the method:That early return skips the reset. With error logging switched off the count therefore climbs on every call and never comes back down, so the third error in a request dies — with a
var_dump()of a backtrace and "loop detected" — even though nothing recursed and the three errors had nothing to do with each other.The count is now balanced in a
finally, which covers that return and also the case where something between the two throws. Nothing else changes: the threshold and the message are what they were, and on the path that already worked the count still goes from one back to zero.Most of the diff is the reindentation for the
try.git diff -wis nine lines.How it turned up
On the Windows job added in #9601. The runner has no
fileinfoextension,Utils::getMimeType()logsrequired_extension_missingwhen it is absent,Avatarcalls it for every gallery avatar, and the third one killed PHPUnit outright:The extension is dealt with separately in #9601. This is the other half: three unrelated errors should not be a loop.
It is not specific to tests or to Windows. Any forum with error logging turned off dies on the third logged error of a request, and shows a raw backtrace while doing it. The same shape is in 2.1's
log_error(), so it has been there a long while.Tests
tests/Unit/ErrorHandlerServiceTest.phplogs five errors with logging off and asserts each returns its message. With logging off the method returns before it touches the database, so this stays on the near side of the line.Against the unfixed code it does not merely fail, it reproduces the bug exactly:
Genuine recursion still ends in the same
die(), which cannot be asserted from inside the process that dies, so that path is unchanged and untested.One thing left alone deliberately: the
var_dump($backtrace)before thedie()writes paths straight to the response. It is worth removing, but it is a different argument from this one and I did not want to bundle it. Happy to follow up.Issues References (Fixes|Related|Closes)