Page MenuHomePhabricator

CampaignEvents should degrade gracefully when querying events for a page fails
Closed, DeclinedPublicBUG REPORT

Description

One of the stack traces for T394503: Database circuit breaking on enwiki (2025-05-16) is a CampaignEvents read path:

from /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/loadmonitor/LoadMonitor.php(125)
#0 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/loadbalancer/LoadBalancer.php(453): Wikimedia\Rdbms\LoadMonitor->scaleLoads(array)
#1 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/loadbalancer/LoadBalancer.php(779): Wikimedia\Rdbms\LoadBalancer->getReaderIndex(string)
#2 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/database/DBConnRef.php(111): Wikimedia\Rdbms\LoadBalancer->getConnectionInternal(int, array, string, int)
#3 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/database/DBConnRef.php(125): Wikimedia\Rdbms\DBConnRef->ensureConnection()
#4 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/database/DBConnRef.php(703): Wikimedia\Rdbms\DBConnRef->__call(string, array)
#5 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/rdbms/database/Database.php(2695): Wikimedia\Rdbms\DBConnRef->getSessionLagStatus()
#6 /srv/mediawiki/php-1.45.0-wmf.1/extensions/CampaignEvents/src/Event/Store/EventStore.php(125): Wikimedia\Rdbms\Database::getCacheSetOptions(Wikimedia\Rdbms\DBConnRef)
#7 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/objectcache/WANObjectCache.php(1846): MediaWiki\Extension\CampaignEvents\Event\Store\EventStore->MediaWiki\Extension\CampaignEvents\Event\Store\{closure}(bool, int, array, null, array)
#8 /srv/mediawiki/php-1.45.0-wmf.1/includes/libs/objectcache/WANObjectCache.php(1650): Wikimedia\ObjectCache\WANObjectCache->fetchOrRegenerate(string, int, Closure, array, array)
#9 /srv/mediawiki/php-1.45.0-wmf.1/extensions/CampaignEvents/src/Event/Store/EventStore.php(135): Wikimedia\ObjectCache\WANObjectCache->getWithSetCallback(string, int, Closure)
#10 /srv/mediawiki/php-1.45.0-wmf.1/extensions/CampaignEvents/src/Event/PageEventLookup.php(63): MediaWiki\Extension\CampaignEvents\Event\Store\EventStore->getEventByPage(MediaWiki\Extension\CampaignEvents\MWEntity\MWPageProxy, int)
#11 /srv/mediawiki/php-1.45.0-wmf.1/extensions/CampaignEvents/src/EventPage/EventPageDecorator.php(157): MediaWiki\Extension\CampaignEvents\Event\PageEventLookup->getRegistrationForLocalPage(MediaWiki\Page\WikiPage)
#12 /srv/mediawiki/php-1.45.0-wmf.1/extensions/CampaignEvents/src/Hooks/Handlers/ArticleViewHeaderHandler.php(35): MediaWiki\Extension\CampaignEvents\EventPage\EventPageDecorator->decoratePage(MediaWiki\Page\WikiPage)
#13 /srv/mediawiki/php-1.45.0-wmf.1/includes/HookContainer/HookContainer.php(155): MediaWiki\Extension\CampaignEvents\Hooks\Handlers\ArticleViewHeaderHandler->onArticleViewHeader(MediaWiki\Page\Article, null, bool)
#14 /srv/mediawiki/php-1.45.0-wmf.1/includes/HookContainer/HookRunner.php(878): MediaWiki\HookContainer\HookContainer->run(string, array)
#15 /srv/mediawiki/php-1.45.0-wmf.1/includes/page/Article.php(708): MediaWiki\HookContainer\HookRunner->onArticleViewHeader(MediaWiki\Page\Article, null, bool)
#16 /srv/mediawiki/php-1.45.0-wmf.1/includes/page/Article.php(551): MediaWiki\Page\Article->generateContentOutput(MediaWiki\User\User, MediaWiki\Parser\ParserOptions, int, MediaWiki\Output\OutputPage, array)
#17 /srv/mediawiki/php-1.45.0-wmf.1/includes/actions/ViewAction.php(80): MediaWiki\Page\Article->view()
#18 /srv/mediawiki/php-1.45.0-wmf.1/includes/actions/ActionEntryPoint.php(728): MediaWiki\Actions\ViewAction->show()
#19 /srv/mediawiki/php-1.45.0-wmf.1/includes/actions/ActionEntryPoint.php(505): MediaWiki\Actions\ActionEntryPoint->performAction(MediaWiki\Page\Article, MediaWiki\Title\Title)
#20 /srv/mediawiki/php-1.45.0-wmf.1/includes/actions/ActionEntryPoint.php(143): MediaWiki\Actions\ActionEntryPoint->performRequest()
#21 /srv/mediawiki/php-1.45.0-wmf.1/includes/MediaWikiEntryPoint.php(198): MediaWiki\Actions\ActionEntryPoint->execute()
#22 /srv/mediawiki/php-1.45.0-wmf.1/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#23 /srv/mediawiki/w/index.php(3): require(string)
#24 {main}

Obviously this is not a solution to the underlying problem, but I wonder if changing CampaignEvents to log and ignore connection errors when looking for events for a page instead of loudly crashing would at least reduce the user-facing impact of these.

Event Timeline

I'm not sure what can be done here, if not avoiding queries if possible, as @Ladsgroup mentioned above.

Strictly speaking, each and every query is susceptible to connection errors, but we don't usually catch those everywhere. I'm not sure if there are any circumstances here that would warrant an exception for this specific query; especially now that the underlying problem (parent task) has been resolved. I'm deferring this judgement to Amir with his DBA hat, though.

Generally speaking catching db queries is highly discouraged: https://www.mediawiki.org/wiki/Database_transactions#Transaction_misuse_errors:

Catching DBError, DBExpectedError, or DBQueryError exceptions without calling rollbackPrimaryChanges() can result in an exception.

Callers might catch DBError exceptions without either re-throwing them or throwing their own version of the error. Doing so is extremely bad practice and can cause all sorts of problems from partial commits to simply spewing up DBTransactionError errors. Only catch DB errors in order to do some cleanup before re-throwing an error or if the database in question is used exclusively by the code catching errors.

Regardless, it would be great if we can fix that issue.

Generally speaking catching db queries is highly discouraged: https://www.mediawiki.org/wiki/Database_transactions#Transaction_misuse_errors:

Yeah, that makes sense to me.

Regardless, it would be great if we can fix that issue.

My question here is if there' something to be fixed, actually. Surely we must change the extension so that it doesn't make this query at all in the majority of cases, but that's tracked in T392784 (which I hope to get to later today or early next week; I just finished going through all that happened while I was OOO).

But for this specific task, as in "catch connection errors", I'd be inclined to close it as declined because connection errors generally shouldn't be caught, and I don't see why the code in question would deserve an exception.

By "that issue" I meant T392784 my apologies for not being clear.

I agree we should close this ticket or e.g. close it as duplicate of T392784 as long as that ticket gets prioritized and fixed.

Per above + T392784 has a patch up.