Page MenuHomePhabricator

MediaWiki failing with "RuntimeException: Output already sent!" after entry point refactor
Closed, ResolvedPublicBUG REPORT

Description

Description
MediWiki core 1.42 has a bug after this patch: https://gerrit.wikimedia.org/r/q/d79af914ff7bb5e8f8f4f2e49f5c4d4c546bc368
Good point: https://gerrit.wikimedia.org/r/q/e66e903ccb8bf5272e0b1fc62c217a48bddfe5b1

Original exception: [75038238c29199cd7918d138] /mw/core/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022   RuntimeException: Output already sent!<br />
Backtrace:<br />
from /Applications/MAMP/htdocs/mw/core/includes/MediaWikiEntryPoint.php(1023)<br />
#0 /Applications/MAMP/htdocs/mw/core/includes/MediaWikiEntryPoint.php(476): MediaWiki\MediaWikiEntryPoint-&gt;flushOutputBuffer()<br />
#1 /Applications/MAMP/htdocs/mw/core/includes/MediaWiki.php(71): MediaWiki\MediaWikiEntryPoint-&gt;doPostOutputShutdown()<br />
#2 /Applications/MAMP/htdocs/mw/core/load.php(61): MediaWiki-&gt;doPostOutputShutdown()<br />
#3 /Applications/MAMP/htdocs/mw/core/load.php(39): wfLoadMain()<br />
#4 {main}<br />
<br />
Exception caught inside exception handler: [75038238c29199cd7918d138] /mw/core/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022   BadMethodCallException: Sessions are disabled for load entry point<br />
Backtrace:<br />
from /Applications/MAMP/htdocs/mw/core/includes/session/SessionManager.php(900)<br />
#0 /Applications/MAMP/htdocs/mw/core/includes/session/SessionManager.php(249): MediaWiki\Session\SessionManager-&gt;getSessionFromInfo(MediaWiki\Session\SessionInfo, MediaWiki\Request\WebRequest)<br />
#1 /Applications/MAMP/htdocs/mw/core/includes/Request/WebRequest.php(865): MediaWiki\Session\SessionManager-&gt;getSessionForRequest(MediaWiki\Request\WebRequest)<br />
#2 /Applications/MAMP/htdocs/mw/core/includes/user/User.php(1067): MediaWiki\Request\WebRequest-&gt;getSession()<br />
#3 /Applications/MAMP/htdocs/mw/core/includes/user/User.php(428): MediaWiki\User\User-&gt;loadFromSession()<br />
#4 /Applications/MAMP/htdocs/mw/core/includes/user/User.php(1576): MediaWiki\User\User-&gt;load()<br />
#5 /Applications/MAMP/htdocs/mw/core/includes/user/User.php(2236): MediaWiki\User\User-&gt;getId()<br />
#6 /Applications/MAMP/htdocs/mw/core/includes/user/Options/UserOptionsManager.php(687): MediaWiki\User\User-&gt;isRegistered()<br />
#7 /Applications/MAMP/htdocs/mw/core/includes/user/Options/UserOptionsManager.php(531): MediaWiki\User\Options\UserOptionsManager-&gt;getCacheKey(MediaWiki\User\User)<br />
#8 /Applications/MAMP/htdocs/mw/core/includes/user/Options/UserOptionsManager.php(159): MediaWiki\User\Options\UserOptionsManager-&gt;loadUserOptions(MediaWiki\User\User, integer)<br />
#9 /Applications/MAMP/htdocs/mw/core/includes/context/RequestContext.php(459): MediaWiki\User\Options\UserOptionsManager-&gt;getOption(MediaWiki\User\User, string)<br />
#10 /Applications/MAMP/htdocs/mw/core/includes/language/Message.php(391): RequestContext-&gt;getLanguage()<br />
#11 /Applications/MAMP/htdocs/mw/core/includes/language/Message.php(1486): Message-&gt;getLanguage()<br />
#12 /Applications/MAMP/htdocs/mw/core/includes/language/Message.php(974): Message-&gt;fetchMessage()<br />
#13 /Applications/MAMP/htdocs/mw/core/includes/language/Message.php(1061): Message-&gt;format(string)<br />
#14 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionRenderer.php(254): Message-&gt;text()<br />
#15 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionRenderer.php(191): MWExceptionRenderer::msg(string, string)<br />
#16 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionRenderer.php(105): MWExceptionRenderer::reportHTML(RuntimeException)<br />
#17 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionHandler.php(133): MWExceptionRenderer::output(RuntimeException, integer)<br />
#18 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionHandler.php(237): MWExceptionHandler::report(RuntimeException)<br />
#19 /Applications/MAMP/htdocs/mw/core/includes/exception/MWExceptionHandler.php(205): MWExceptionHandler::handleException(RuntimeException, string)<br />
#20 [internal function]: MWExceptionHandler::handleUncaughtException(RuntimeException)<br />
#21 {main}<br />

Event Timeline

Besides the Output already sent error, this makes the error handling very ungraceful:

dev.wiki.local.wmftest.net_10048_wiki_Special_Log_type=mwoauthconsumer&user=&page=&wpdate=&tagfilter=&wpfilters%5B%5D=newusers&wpFormIdentifier=logeventslist.png (4×3 px, 1 MB)

Tgr renamed this task from Uncaught SyntaxError: Unexpected identifier 'internal' to RuntimeException: Output already sent!.Feb 4 2024, 7:19 AM
Tgr renamed this task from RuntimeException: Output already sent! to MediaWiki failing with "RuntimeException: Output already sent!" after entry point refactor.

The stack trace for the screenshot:

[05ddb74fda2aa350efb9da7b] /wiki/Special:Log?type=mwoauthconsumer&user=&page=&wpdate=&tagfilter=&wpfilters%5B%5D=newusers&wpFormIdentifier=logeventslist RuntimeException: Output already sent!

Backtrace:

from /vagrant/mediawiki/includes/MediaWikiEntryPoint.php(1025)
#0 /vagrant/mediawiki/includes/MediaWikiEntryPoint.php(478): MediaWiki\MediaWikiEntryPoint->flushOutputBuffer()
#1 /vagrant/mediawiki/includes/MediaWikiEntryPoint.php(454): MediaWiki\MediaWikiEntryPoint->doPostOutputShutdown()
#2 /vagrant/mediawiki/includes/MediaWikiEntryPoint.php(209): MediaWiki\MediaWikiEntryPoint->postOutputShutdown()
#3 /vagrant/mediawiki/index.php(57): MediaWiki\MediaWikiEntryPoint->run()
#4 /var/www/w/index.php(5): require(string)
#5 {main}

The load.php "Sessions are disabled" error seems to be happening on every page, the index.php one seems to be limited to special pages.

Tgr triaged this task as High priority.Feb 4 2024, 7:25 AM

Needs to be fixed before the next train.

The Sessions are disabled for load entry point part is a separate bug, I think - MWExceptionRenderer should handle being called from load.php more gracefully.

Change 323057 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] Limit language logic when displaying exceptions / outage messages

https://gerrit.wikimedia.org/r/323057

Caused by rMW24d0aee05e61: entrypoint: Isolate entry points from PHP runtime for testing incorrectly assuming that whenever MediaWiki::doPostOutputShutdown() is called, the response hasn't been sent yet.

Change 996018 had a related patch set uploaded (by Gergő Tisza; author: Gergő Tisza):

[mediawiki/core@master] Don't assume no prior output in MWEntryPoint::flushOutputBuffer()

https://gerrit.wikimedia.org/r/996018

Change 996018 merged by jenkins-bot:

[mediawiki/core@master] Don't assume no prior output in MWEntryPoint::flushOutputBuffer()

https://gerrit.wikimedia.org/r/996018

Change 323057 merged by jenkins-bot:

[mediawiki/core@master] Limit language logic when displaying exceptions / outage messages

https://gerrit.wikimedia.org/r/323057

matmarex assigned this task to Tgr.

@Tgr Thank you for fixing this!

I still think that calling flushOutputBuffer() after the output has already been sent is dubious. But we can deal with that later.

Caused by rMW24d0aee05e61: entrypoint: Isolate entry points from PHP runtime for testing incorrectly assuming that whenever MediaWiki::doPostOutputShutdown() is called, the response hasn't been sent yet.

Hm... so, the name is a lie? Can we fix that?

Yeah the logic is pretty confusing, at a glance the flushOutputBuffer() call in doPostOutputShutdown() seems superfluous but I'm not familiar with this part of the codebase so I'm likely to miss something. Maybe it depends on whether PHP output compression is enabled?

Yeah the logic is pretty confusing, at a glance the flushOutputBuffer() call in doPostOutputShutdown() seems superfluous but I'm not familiar with this part of the codebase so I'm likely to miss something. Maybe it depends on whether PHP output compression is enabled?

Perhaps that call is just there for good measure?

I'm tempted to put the check back, but simply return if there is no pending output.

Change 997813 had a related patch set uploaded (by Daniel Kinzler; author: Daniel Kinzler):

[mediawiki/core@master] flushOutputBuffer: improve error handling

https://gerrit.wikimedia.org/r/997813

Change 997813 merged by jenkins-bot:

[mediawiki/core@master] flushOutputBuffer: improve error handling

https://gerrit.wikimedia.org/r/997813