Page MenuHomePhabricator

JsonConfig emits PHP error "Cannot access property on non-object" in JCApi::addStatusConf
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

Request ID: W5-vPArAIFoAAGhDdHIAAABF

message
PHP Notice: Cannot access property on non-object

There are close variations of this error from the same method but different line numbers.

JCApi.php:32 Trace
#0 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(32): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(64): JsonConfig\JCApi::addStatusConf(stdClass)
#2 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(1587): JsonConfig\JCApi->execute()
#3 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(531): ApiMain->executeAction()
#4 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#5 /srv/mediawiki/php-1.32.0-wmf.20/api.php(87): ApiMain->execute()
#6 /srv/mediawiki/w/api.php(3): include(string)
JCApi.php:33 Trace
#0 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(33): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(64): JsonConfig\JCApi::addStatusConf(stdClass)
#2 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(1587): JsonConfig\JCApi->execute()
#3 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(531): ApiMain->executeAction()
#4 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#5 /srv/mediawiki/php-1.32.0-wmf.20/api.php(87): ApiMain->execute()
#6 /srv/mediawiki/w/api.php(3): include(string)
JCApi.php:34 Trace
#0 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(34): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.32.0-wmf.20/extensions/JsonConfig/includes/JCApi.php(64): JsonConfig\JCApi::addStatusConf(stdClass)
#2 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(1587): JsonConfig\JCApi->execute()
#3 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(531): ApiMain->executeAction()
#4 /srv/mediawiki/php-1.32.0-wmf.20/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#5 /srv/mediawiki/php-1.32.0-wmf.20/api.php(87): ApiMain->execute()
#6 /srv/mediawiki/w/api.php(3): include(string)

Notes

Different wikis, mostly API.

Event Timeline

Krinkle updated the task description. (Show Details)

Analysis by @TheDJ.

  • Example output from that query:
{   "models": { … },
    "titleMap": {
        "480": [],
        "486": [
            {   "model": "Tabular.JsonConfig",
                "namespace": 486,
                "nsName": "Data",
                "nsTalk": "default",
                "isLocal": false,
                "cacheExp": 86400,
                "cacheKey": "",
                "flaggedRevs": false,
                "remote": {
                    "url": "https://commons.wikimedia.org/w/api.php",
                    "username": false,
                    "password": false
                },
                "store": {
                    "cacheNewValue": null,
                    "notifyUrl": null,
                    "notifyUsername": true,
                    "notifyPassword": true
                }
            },

The code in question is from extensions/JsonConfig/JCApi.php:

		if ( isset( $conf->store ) ) {
			$res['store'] = [
				'cacheNewValue' => $conf->store->cacheNewValue,
				'notifyUrl' => $conf->store->notifyUrl,
				'notifyUsername' => $conf->store->notifyUsername !== '', // true or false
				'notifyPassword' => $conf->store->notifyPassword !== '', // true or false
			];
		}

Virtually always when this API is called, $conf->store is set, but set to boolean false, not an object. As such, all four of these members are non-existent and implicitly null.

This means cacheNewValue and notifyUrl are output as null. And notifyUsername is unexpectedly set to true instead of false, because the code assumes empty string as the bottom value, which null is not.

Side note: This is still broadcasting https://zero.wikimedia.org/w/api.php, which should presumably be disabled at some point?

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:08 PM

JsonConfig is the most common producer of errors in the production logs over the past few weeks, this makes deployments more difficult and risky than they need to be. Tagging Product-Infra per mw:Maintainers page to hopefully look into this.

Change 545848 had a related patch set uploaded (by MSantos; owner: MSantos):
[mediawiki/extensions/JsonConfig@master] Fix PHP production error and update documentation

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

Change 545848 merged by jenkins-bot:
[mediawiki/extensions/JsonConfig@master] Fix PHP production error and update documentation

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

Last time this error was logged was 2019-09-22T12:25:51. Please reopen if needed.