Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I was trying to solve a testbot problem for somebody, tailing the apache error log on the test suite, and was surprised to find many, many uncaught PHP exceptions in there. I wouldn't think this would be normal or right.
It pollutes the error log, of course, but it seems to me it's a sign of a design problem.
[Thu Oct 04 14:22:11 2012] [error] [client 10.20.0.167] Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException: "" at /var/lib/drupaltestbot/sites/default/files/checkout/core/lib/Drupal/Core/EventSubscriber/AccessSubscriber.php line 34
repeated lot of times.
Comment | File | Size | Author |
---|---|---|---|
#25 | 1803338.exception-listener.25.patch | 4.44 KB | katbailey |
#23 | 1803338.exception-listener.22.patch | 4.45 KB | katbailey |
#21 | 1803338.patch | 4.45 KB | chx |
#17 | 1803338.patch | 5.6 KB | chx |
#14 | 1803338.patch | 5.6 KB | chx |
Comments
Comment #1
jthorson CreditAttribution: jthorson commentedThis is a debug_backtrace() from each of the Access_Subscriber line 34 uncaught exceptions. I haven't parsed through it to see if it tells us anything useful (since the format_debug() version certainly didn't).
http://drupaltestbot-dev-mysql.osuosl.test/uncaughtexception.log
EDIT: The above link requires OSUOSL access.
Comment #2
chx CreditAttribution: chx commentedThe chain of execution is this: AccessSubscriber.php throws a 403, handleException catches it, dispatches a KernelEvents::EXCEPTION event and causes the ExceptionListener to fire which calls error_log.
Possible solutions include overriding handleException in our kernel not to dispatch the EXCEPTION event. I do not see a point really.
Comment #3
chx CreditAttribution: chx commentedHanding it over to Crell for guidance.
Comment #4
chx CreditAttribution: chx commentedAnd this is major if not critical because it causes our testbot disks to fill up. Ridiculous...
Comment #5
jthorson CreditAttribution: jthorson commentedWhen investigating this, please also consider the NotFoundHttpException chain, which I assume is a similar chain of execution.
Comment #6
Crell CreditAttribution: Crell commentedNot dispatching an EXCEPTION event is a non-starter. But perhaps an alternate ExceptionListener that only calls error_log() for really exceptional exceptions?
Comment #7
chx CreditAttribution: chx commentedTell me how to change the even subscribers and I will.
Comment #8
chx CreditAttribution: chx commentedCrell's short recipe: Subclass ExceptionListener, stick it in the Core\EventSubscriber namespace, and update the code in the DIC registration that registers that listener.
He also approved my battle plan to copy the whole ExceptionListener class and wrap the error_log in an if (!httpexception)
Comment #9
Crell CreditAttribution: Crell commentedActually, why copy instead of subclass and override?
Comment #10
chx CreditAttribution: chx commentedBecause the whole class is one method :P (almost)
Comment #11
Crell CreditAttribution: Crell commentedEh, OK, I suppose that's a reason.
Comment #12
chx CreditAttribution: chx commentedComment #14
chx CreditAttribution: chx commentedComment #15
chx CreditAttribution: chx commentedComment #17
chx CreditAttribution: chx commentedThe bot is finicky today ;) what's a syntax error or two in the critical patch in the critical path, meh.
Comment #18
Crell CreditAttribution: Crell commentedAh ha, now I see why this is happening, and why Symfony sites don't melt servers. :-) The assumption is that you'd always have a logger object, so that code path doesn't get called. A Symfony site would. We do not yet. Related: #1289536: Switch Watchdog to a PSR-3 logging framework
Still, we shouldn't hold up on that. Maybe drop a @todo noting why we have to do it so we can back out later. And removing the (c) Fabien Potencier block and such. :-)
Comment #19
katbailey CreditAttribution: katbailey commentedIf we're going to bother introducing our own class for this - why not leave out the $logger property altogether? Copying the entire class and leaving it exactly as is bar this one little change seems crazy when half of that code will never run.
Comment #20
Crell CreditAttribution: Crell commentedThat makes even more sense. If we add a logger, we can drop this class and go back to the Symfony one, logger and all.
Comment #21
chx CreditAttribution: chx commentedTook the axe to it.
Comment #23
katbailey CreditAttribution: katbailey commentedI think it makes sense to remove the logger property from the class entirely. And so if we're going that far it seems reasonable to "adopt" the class as our own, i.e. with Drupal coding standards instead of Symfony's.
Comment #24
Crell CreditAttribution: Crell commentedMissed the coding standards for classes and functions. :-)
I rechecked, and the Symfony logger is still logging for HTTP 500 errors. I don't know if we want to do that or not. We need to reroll for formatting anyway, so we can add that here if we want, or not.
I know this is in Symfony, but it looks wrong. We're not rethrowing an exception, we're swallowing it. Rightly or wrongly, the comment doesn't match the code. (That said, it is what Symfony is doing, so I'm OK with leaving it as is and opening up an upstream issue to fix the comment at least.)
Otherwise this looks good.
Comment #25
katbailey CreditAttribution: katbailey commentedFixed
I think that makes sense, added.
Actually both that comment and the one above it were bothering me, so I got rid of the second one seeing as it's incorrect and I don't think we really need a comment there at all, and I changed the previous one to make grammatical sense.
Comment #26
Crell CreditAttribution: Crell commentedYay for fewer gigabyte-sized log files.
Comment #27
jthorson CreditAttribution: jthorson commentedConfirmed that this does indeed prevent the uncaught AccessDeniedHttpException from hitting the testbot apache log on at least one of the tests which was causing it earlier.
Comment #28
webchickI was going to mark needs work for this, only to discover that this is what passes for PHPDoc in the Symfony project. :\ Egads.
Brainstormed with chx and jthorson on IRC and came up with "Override of Symfony EventListener class to kill 403 and 404 from server logs." Fixed on commit.
Committed and pushed to 8.x. Yay fewer hard drive fill-ups! :)
Comment #29.0
(not verified) CreditAttribution: commentedtidied up