Page MenuHomePhabricator

Wikibase CI on REL1_40 broken: QUnit tests failing to run
Closed, ResolvedPublic

Description

On REL1_40 the CI for the Wikibase fails with the QUnit tests seemingly failing to run / timing out:

16:47:05 07 02 2024 16:47:05.028:DEBUG [middleware:source-files]: Requesting /load.php?modules=vue%2Cvuex%2Cwikibase%7Cwikibase.EntityInitializer%2CSite%2CWikibaseContentLanguages%2CbuildErrorOutput%2Cdatamodel%2CgetLanguageNameByCode%2CgetUserLanguages%2Clexeme%2Cserialization%2Csites%2Ctemplates%7Cwikibase.api.RepoApi%2CValueCaller%7Cwikibase.entityChangers.EntityChangersFactory%7Cwikibase.experts.Entity%2CForm%2CItem%2CLexeme%2CProperty%2CSense%2C__namespace%2Cmodules%7Cwikibase.formatters.ApiValueFormatter%7Cwikibase.lexeme.datamodel%2CgetDeserializer%2Clexemeview%7Cwikibase.lexeme.view.ViewFactoryFactory%7Cwikibase.templates.lexeme%7Cwikibase.ui.entityViewInit%7Cwikibase.utilities.ClaimGuidGenerator%7Cwikibase.view.ControllerViewFactory%2CReadModeViewFactory%2C__namespace&version=m5643
16:47:05 07 02 2024 16:47:05.028:DEBUG [middleware:source-files]: Fetching /load.php
16:47:05 07 02 2024 16:47:05.028:DEBUG [proxy]: proxying request - /load.php?modules=vue%2Cvuex%2Cwikibase%7Cwikibase.EntityInitializer%2CSite%2CWikibaseContentLanguages%2CbuildErrorOutput%2Cdatamodel%2CgetLanguageNameByCode%2CgetUserLanguages%2Clexeme%2Cserialization%2Csites%2Ctemplates%7Cwikibase.api.RepoApi%2CValueCaller%7Cwikibase.entityChangers.EntityChangersFactory%7Cwikibase.experts.Entity%2CForm%2CItem%2CLexeme%2CProperty%2CSense%2C__namespace%2Cmodules%7Cwikibase.formatters.ApiValueFormatter%7Cwikibase.lexeme.datamodel%2CgetDeserializer%2Clexemeview%7Cwikibase.lexeme.view.ViewFactoryFactory%7Cwikibase.templates.lexeme%7Cwikibase.ui.entityViewInit%7Cwikibase.utilities.ClaimGuidGenerator%7Cwikibase.view.ControllerViewFactory%2CReadModeViewFactory%2C__namespace&version=m5643 to 127.0.0.1:9413
16:47:05 Chrome Headless 90.0.4430.212 (Linux x86_64) INFO: 'You are running a development build of Vue.
16:47:05 Make sure to use the production build (*.prod.js) when deploying for production.'
16:47:05 Chrome Headless 90.0.4430.212 (Linux x86_64) WARN: 'This page is using the deprecated ResourceLoader module "jquery.tipsy".'
16:47:05 Chrome Headless 90.0.4430.212 (Linux x86_64) WARN: 'This page is using the deprecated ResourceLoader module "jquery.ui".
16:47:05 Please use OOUI instead.'
16:47:05 07 02 2024 16:48:05.883:WARN [Chrome Headless 90.0.4430.212 (Linux x86_64)]: Disconnected (0 times) , because no message in 60000 ms.
16:48:05 Chrome Headless 90.0.4430.212 (Linux x86_64) ERROR
16:48:05   Disconnected , because no message in 60000 ms.
16:48:05 07 02 2024 16:48:05.886:DEBUG [Chrome Headless 90.0.4430.212 (Linux x86_64)]: CONFIGURING -> DISCONNECTED
16:48:05 07 02 2024 16:48:05.889:DEBUG [launcher]: CAPTURED -> BEING_KILLED
16:48:05 07 02 2024 16:48:05.889:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
16:48:05 07 02 2024 16:48:05.889:DEBUG [Chrome Headless 90.0.4430.212 (Linux x86_64)]: DISCONNECTED -> DISCONNECTED
16:48:05 
16:48:05 Finished in 1 min 2.232 secs / 0 secs @ 16:48:05 GMT+0000 (Coordinated Universal Time)

from https://integration.wikimedia.org/ci/job/quibble-composer-mysql-php74-noselenium-docker/43732/console for {DNM} Empty commit to test CI on REL1_40

Downstream from that failure for Wikibase is CI on REL1_40 also failing for the ArticlePlaceholder extension, specifically for a LibraryUpgrader change to update some dependencies, which is how that problem was discovered in the first place: build: Updating npm dependencies.

Note also that the same problem seems to exist for REL1_39, given that the respective change for ArticlePlaceholder is failing with the same error: build: Updating npm dependencies

Acceptance Criteria:

  • CI for Wikibase on REL1_40 is green
  • CI for Wikibase on REL1_39 is green

Event Timeline

karapayneWMDE subscribed.

triage - is there urgency here? we can maybe handover the article placeholder topic to WD&WMP

Since we want to backport some fixes to the release branches soon, it would be good to have green CI there. If we can’t figure out the problem and don’t want to spend too much time on it, maybe we’ll end up just disabling the tests temporarily…

Look what I found in mw-error.log (linked under “build artifacts” from the overview page of a failed build like this one):

Fatal Error from line 71 of /workspace/src/includes/xml/XmlJsCode.php: Allowed memory size of 134217728 bytes exhausted (tried to allocate 21670080 bytes)
#0 [internal function]: MWExceptionHandler::handleFatalError()
#1 {main}

Is this just the same issue as T354179 in another place?

Also, that build I just linked is from this REL1_40 change – specifically from gate-and-submit: the normal test build worked. So maybe this only fails some of the time? (On the equivalent REL1_39 build, the normal test build already failed.)

On a recheck, the REL1_40 change now failed both in test and in gate-and-submit, so it looks like I just got lucky the first time.

I had a poke around at this the last days. Quick status update from my side.

Running Quibble locally it's possible to reproduce the issue:

mkdir -p src && mkdir -p cache && mkdir -p log && mkdir -p ref

docker run --entrypoint=quibble-with-supervisord \
  --tmpfs /workspace/db:size=320M \
  --volume "$(pwd)"/src:/workspace/src \
  --volume "$(pwd)"/cache:/cache \
  --volume "$(pwd)"/log:/workspace/log \
  --volume "$(pwd)"/ref:/srv/git:ro \
  --security-opt seccomp=unconfined \
  --env-file=.env --init --rm \
  docker-registry.wikimedia.org/releng/quibble-buster-php74:1.6.0-s6 \
  --packages-source composer \
  --db mysql --db-dir /workspace/db \
  --git-parallel=8 \
  --run qunit

.env:

ZUUL_PROJECT=mediawiki/extensions/Wikibase
ZUUL_BRANCH=REL1_40
EXT_NAME=Wikibase
SKIN_DEPENDENCIES=mediawiki/skins/MinervaNeue\nmediawiki/skins/Vector
EXT_DEPENDENCIES=mediawiki/extensions/CirrusSearch\nmediawiki/extensions/VisualEditor\nmediawiki/extensions/Wikibase\nmediawiki/extensions/Scribunto\nmediawiki/extensions/Elastica\nmediawiki/extensions/Echo\nmediawiki/extensions/DiscussionTools\nmediawiki/extensions/Linter

I created a local version of the Quibble container with XDebug enabled and was able to get this stack trace for the failed request:

I've also been able to generate profiler output for failed and successful requests, but they are ~400MB in size so I will not include them here.

Running the QUnit tests hits the 128MB memory limit for the container when a request like this needs to be served:

http://127.0.0.1:9413/load.php?modules=mediawiki.language%2CmessagePoster%2Cpulsatingdot%2Cqunit-testrunner%2Crouter%2Cstorage%2Ctemplate%2Ctoc%2Cuser%2Cutil%2CvisibleTimeout%2Cwidgets%7Cmediawiki.language.months%2Cnames%2CspecialCharacters%2Ctestdata%7Cmediawiki.libs.guiders%2Cjpegmeta%2Cpluralruleparser%7Cmediawiki.page.gallery.styles%7Cmediawiki.page.ready%7Cmediawiki.page.watch.ajax%7Cmediawiki.rcfilters.filters.ui%7Cmediawiki.skinning.content.parsoid%7Cmediawiki.template.handlebars%2Cmustache%2Cvue%7Cmediawiki.ui.button%2Cicon%7Cmediawiki.widgets.AbandonEditDialog%2CCategoryMultiselectWidget%2CDateInputWidget%2CMediaSearch%2CTable%2CUserInputWidget%2Cstyles%7Cmediawiki.widgets.DateInputWidget.styles%7Cmobile.ooui.icons%7Cmobile.pagelist.styles%7Cmobile.pagesummary.styles%7Cmobile.placeholder.images%7Cmobile.startup%7Cmobile.startup.images%7Cmoment%2Coojs%2Coojs-ui%2Coojs-ui-core%2Coojs-ui-toolbars%2Coojs-ui-widgets%2Coojs-ui-windows%2Cpapaparse%2Crangefix%2Csinonjs%2Cspark-md5%2CtreeDiffer%2Cunicodejs%2CvalueFormatters%2CvalueParsers%7Cmw.config.values.wbDataTypes%2CwbRefTabsEnabled%2CwbRepo%2CwbSiteDetails%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui-toolbars.icons%7Coojs-ui-widgets.icons%7Coojs-ui-windows.icons%7Coojs-ui.styles.icons-accessibility%2Cicons-alerts%2Cicons-content%2Cicons-editing-advanced%2Cicons-editing-citation%2Cicons-editing-core%2Cicons-editing-list%2Cicons-editing-styling%2Cicons-interactions%2Cicons-layout%2Cicons-media%2Cicons-moderation%2Cicons-movement%2Cicons-user%2Cindicators%7Cskins.minerva.messageBox.styles%7Csocket.io%7Ctest.ArticlePlaceholder%2CCentralAuth%2CCite%2CDiscussionTools%2CEcho%2CEventLogging%2CFlow%2CGuidedTour%2CMediaWiki%2CMinervaNeue%2CTemplateData%2CThanks%2CUniversalLanguageSelector%2CVisualEditor%2CWikiEditor%2CWikibaseClient%2CWikibaseLexeme%2CWikibaseRepository%2CWikimediaEvents%7Cutil.ContentLanguages%2CExtendable%2CMessageProvider%2CMessageProviders%2CNotifier%2ChighlightSubstring%2Cinherit%7CvalueParsers.ValueParserStore%2Cparsers&version=1a741

In particular, loading the modules and dependencies for the test.DiscussionTools QUnit tests loads in about 150 files, some of which are many megabytes in size. The ResourceLoader loads these from disk into memory, duplicates the strings in memory while it wraps and unwraps them in XmlJsCode objects (HtmlJsCode on master), and it's eventually a call to implode just before the output is sent to the client which causes the process to ask for too much memory. The memory usage is not helped by the fact that the Module objects keep a cache of the content, and the ResourceLoader keeps a cache of modules. So my working theory is that in the first pass, where we have to warm those caches and manipulate all the strings in memory, for particularly long module lists, there are just too many bytes involved.

My plan for next week is to attach gdb and get a heap dump to see where all the memory is going. There might be some low-hanging fruit for optimising the way we use memory.

Also worth noting:

  • Running Quibble without php-fpm doesn't have this issue. I'm not currently sure why this is - it could be an implementation quirk, or it could be that we're right at the boundary of the 128MB and php-fpm just has a little bit extra overhead. I haven't looked deeply into the memory accounting there
  • Making a second request to the same URL works fine. Presumably serving the modules from the heap-cached Module objects uses less memory than streaming them in from disk and generating the memory representation and caching that before serving the module.

Change 1010179 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/core@master] Rewrite HtmlJsCode::encodeObject to reduce memory usage

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

Change 1010186 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/core@REL1_40] Rewrite XmlJsCode::encodeObject to reduce memory usage

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

Change 1008855 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/EntitySchema@master] Remove dispensable start-up request introduced as CI workaround

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

A few more updates here. I looked at the memory usage for the above request (in the failing case), and instrumented the run with repeated calls to memory_get_usage() in the interactive debugger in PHPStorm. What I saw there is that in Module.php::getModuleContent for the test.DiscussionTools module, the memory usage goes up dramatically:

	public function getModuleContent( Context $context ) {
		$contextHash = $context->getHash();  // <--- MEMORY USAGE 16.76 MB
		// Cache this expensive operation. This calls builds the scripts, styles, and messages
		// content which typically involves filesystem and/or database access.
		if ( !array_key_exists( $contextHash, $this->contents ) ) {
			$this->contents[$contextHash] = $this->buildContent( $context );
		}
		return $this->contents[$contextHash]; // <-- MEMORY USAGE 45.06 MB
	}

so we know here that just the content of the files is about 30MB of data that we need to reformat in memory before streaming back to the client. When we then get to XmlJsCode.php::encodeObject, the situation is already worse and about to get critical:

	public static function encodeObject( $obj, $pretty = false ) {
                // $obj in this case is an array with 147 keys corresponding to different files / modules
		$parts = [];
		foreach ( $obj as $key => $value ) {
			$parts[] =
				( $pretty ? '    ' : '' ) .
				Xml::encodeJsVar( $key, $pretty ) .
				( $pretty ? ': ' : ':' ) .
				Xml::encodeJsVar( $value, $pretty );
		}
                // By the time we get down here -> MEMORY USAGE 65.93 MB
		return new self(
			'{' .
			( $pretty ? "\n" : '' ) .
			implode( $pretty ? ",\n" : ',', $parts ) . // The implode itself then doubles the space required for
			( $pretty ? "\n" : '' ) .                  // this 20MB string manipulation -> MEMORY USAGE 86.39
			'}'
		);
	}

With memory_limit at 128MB, at least in the php-fpm environment, the implode pushes us past the limit.

The proposed patch makes better use of memory inside XmlJsCode.php so that we don't immediately explode at that point. Unfortunately, that doesn't eliminate the issue - instead, we run out of memory in my local testing inside JavaScriptMinifier::minifyInternal - see attached:

The logs from the CI run show an error at ResourceLoader.php#L851, which is echo $response;

And just to make this more concrete and compact, the following request:

http://127.0.0.1:9413/load.php?modules=test.DiscussionTools&version=1a741

has a peak memory consumption of 121.81MB (with the old implementation of {Html,Xml}JsCode::encodeObject, 97.78MB with the new).

The code on master for the same request has a peak memory consumption of 89.16MB without the patch and the patch doesn't seem to have an impact on the peak memory consumption - there has been a substantial refactor of the ResourceLoader that reduces the amount of in-memory string manipulation that happens. See T47514

I start to be convinced that the right option here is either to disable the DiscussionTools tests for the old branches or increase the memory for the containers running CI for those branches until such time as 1.42 is the oldest version we're testing.

This is an exact duplicate of T356402: [ES] Investigate OutOfMemory error in browser test, remove workaround which itself follows up T354179: EntitySchema CI broken on master with OutOfMemory error in browser test.

From my comment at T356402#9536659 , the php-fpm memory_limit is set by Debian at 128M and per Lucas, we should raise it :)

Change 1012674 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

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

Change 1010186 abandoned by Arthur taylor:

[mediawiki/core@REL1_40] Rewrite XmlJsCode::encodeObject to reduce memory usage

Reason:

Change is not necessary since we bumped the CI memory limit instead

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

Change 1010179 abandoned by Arthur taylor:

[mediawiki/core@master] Rewrite HtmlJsCode::encodeObject to reduce memory usage

Reason:

Patch doesn't impact peak memory usage and decreases readability.

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

REL1_40 is now passing and REL1_39 is failing but for reasons unrelated to the out-of-memory. T360435 tracks the remaining test failures, but from the point of view of memory usage, this is now resolved with the CI patches from @hashar .

Alright, then I think we can close this task?

Agreed. I'll move it to tech verification and do a one more set of empty changes against REL1_39 and REL1_40 to confirm, then I'll close it.

Change #1016923 had a related patch set uploaded (by Arthur taylor; author: Arthur taylor):

[mediawiki/extensions/Wikibase@REL1_40] [DNM] test empty commit

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

Just retested. CI on REL1_40 is green, and REL1_39 fails for reasons unconnected to QUnit. Marking this as done.

Change #1016923 abandoned by Arthur taylor:

[mediawiki/extensions/Wikibase@REL1_40] [DNM] test empty commit

Reason:

just a test

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

Change #1012674 abandoned by Arthur taylor:

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

Reason:

just a test

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

Change #1012674 restored by Arthur taylor:

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

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

Change #1012674 abandoned by Arthur taylor:

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

Reason:

Tests are now passing

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

Change #1012674 restored by Itamar Givon:

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

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

Change #1012674 abandoned by Itamar Givon:

[mediawiki/extensions/Wikibase@REL1_39] [DNM] test empty commit

Reason:

Revived the wrong change

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