Page MenuHomePhabricator

PHP Warning: array_intersect_key() expects parameter 1 to be an array or collection
Closed, ResolvedPublic3 Story Points

Description

An error is frequently (0-9 times/day) occurring in logstash. It might be exposing a bug that we are not aware of, and is making it harder to see other bugs in our error logs so we should aim to investigate it and squash it!

Logstash

Stack trace:

0 /srv/mediawiki/php-1.29.0-wmf.16/extensions/MobileFrontend/includes/api/ApiMobileView.php(129): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.29.0-wmf.16/includes/api/ApiMain.php(1543): ApiMobileView->execute()
#2 /srv/mediawiki/php-1.29.0-wmf.16/includes/api/ApiMain.php(544): ApiMain->executeAction()
#3 /srv/mediawiki/php-1.29.0-wmf.16/includes/api/ApiMain.php(515): ApiMain->executeActionWithErrorHandling()
#4 /srv/mediawiki/php-1.29.0-wmf.16/api.php(83): ApiMain->execute()
#5 /srv/mediawiki/w/api.php(3): include(string)
#6 {main}

Troublesome line appears to be:

$pageProps = array_intersect_key( $data['pageprops'], array_flip( $propNames ) );

Throwing

ErrorException from line 129 of /srv/mediawiki/php-1.29.0-wmf.21/extensions/MobileFrontend/includes/api/ApiMobileView.php: PHP Warning: array_intersect_key() expects parameter 1 to be an array or collection

Parameter 1 is $data['pageprops']
This will either be the result of ApiMobileView::getData which should be an empty list or the result of ParserOutput::getProperties
It's not clear why this is happening so additional logging may be required.

Spend no more than 3hrs on this. If you find yourself doing that, simply type check before calling array_intersect_key and add explicitly log the value of argument 1. Don't fall down the MediaWiki rabbit hole, trying to work out why.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 21 2017, 7:38 PM
Jdlrobson triaged this task as Normal priority.Mar 21 2017, 7:38 PM
Jdlrobson moved this task from Triaged but Future to Upcoming on the Readers-Web-Backlog board.
Jdlrobson updated the task description. (Show Details)Apr 24 2017, 7:25 PM
Jhernandez updated the task description. (Show Details)Apr 25 2017, 4:47 PM
MBinder_WMF set the point value for this task to 3.Apr 25 2017, 4:50 PM
Jdlrobson updated the task description. (Show Details)May 2 2017, 6:39 PM
Jdlrobson updated the task description. (Show Details)May 2 2017, 6:52 PM
Jdlrobson updated the task description. (Show Details)May 4 2017, 12:11 AM

^ See email: Friday sprint review

Looks like this and T166530 are the same
If you set $data['pageprops'] = 'foo';

you can generate both errors when you hit http://localhost:8888/w/api.php?action=mobileview&format=json&page=Headings%20are%20broke&prop=pageprops

Warning: array_intersect_key(): Argument #1 is not an array in /Users/jrobson/git/core/extensions/MobileFrontend/includes/api/ApiMobileView.php on line 132

Catchable fatal error: Argument 1 passed to ApiResult::setArrayType() must be of the type array, null given, called in /Users/jrobson/git/core/extensions/MobileFrontend/includes/api/ApiMobileView.php on line 135 and defined in /Users/jrobson/git/core/includes/api/ApiResult.php on line 728

So next question is where does pageprops come from...
It seems to be set at the bottom of ApiMobileView::getData and is either empty array or the result of $parserOutput->getProperties()
I don't see any reason why $parserOutput->getProperties() would return anything other than an array (unless something is doing $parserOutput->mProperties = null (yuk) since since mProperties is a public property.

The ApiMobileView::getData method however can return early without setting it under certain conditions.

it seems that these conditions are:

  • the page is a redirect
  • the namespace is greater than 0

Change 356481 had a related patch set uploaded (by Jdlrobson; owner: Jdlrobson):
[mediawiki/extensions/MobileFrontend@master] When page properties are not available do not throw exceptions

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

pmiazga added a subscriber: pmiazga.

Reviewed, looks ok

Change 356481 merged by jenkins-bot:
[mediawiki/extensions/MobileFrontend@master] When page properties are not available do not throw exceptions

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

bmansurov claimed this task.Jun 1 2017, 5:04 PM

Will sign off once the patch is in production.

Will sign off tomorrow as the changes haven't hit production yet.

phuedx added a subscriber: phuedx.Jun 9 2017, 9:12 AM

Looking at the the Reading Web Logstash dashboard for the last 12 hours, it looks like these errors have disappeared.

bmansurov closed this task as Resolved.Jun 9 2017, 1:52 PM
bmansurov removed bmansurov as the assignee of this task.
bmansurov added a subscriber: bmansurov.

Thanks, @phuedx! That link is still clean for the last 12 hours.

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