Page MenuHomePhabricator

ApiEditPage triggers 500 Internal Server Error when attempting to add text to a page over a redirect
Closed, ResolvedPublic

Description

Logfile (Firebug output) and Error codes from the response 500-error site

I wrote http://commons.wikimedia.org/wiki/User:Rillke/AxUserMsg.js

When I try this on my talk-page it works but the response is a server-error instead of a normal one. I assume the problem arises because it's a redirect.

But nevertheless there are other users complaining getting server error 502 when attempting to add text to a discussion page that is not a redirect:
http://commons.wikimedia.org/wiki/MediaWiki_talk:AjaxQuickDelete.js#502_error

A description/ log of the error I got is attached.

Sincerely Rillke


Version: 1.17.x
Severity: normal

Attached:

Details

Reference
bz29278

Event Timeline

bzimport raised the priority of this task from to High.Nov 21 2014, 11:26 PM
bzimport set Reference to bz29278.

500: PHP fatal error in /usr/local/apache/common-local/php-1.17/includes/json/Services_JSON.php line 497:
Object of class Services_JSON_Error could not be converted to string

(In reply to comment #1)

500: PHP fatal error in
/usr/local/apache/common-local/php-1.17/includes/json/Services_JSON.php line
497:
Object of class Services_JSON_Error could not be converted to string

I've fixed the cause of this specific error (failure to convert to string) in r89553. Could you retry your request? You'll probably get an error again, but it should be the 'real' error this time.

Created attachment 8628
Logfile (Firebug output) and Error codes from the response 502-error site

Attached:

Now tested again and got 502-error:
POST http://commons.wikimedia.org/w/api.php, from 91.198.174.40 via sq34.wikimedia.org (squid/2.7.STABLE9) to 10.2.1.22 (10.2.1.22)
Error: ERR_ZERO_SIZE_OBJECT, errno [No Error] at Mon, 06 Jun 2011 18:10:16 GMT

FYI, you should ALWAYS send the token as the last parameter

See https://bugzilla.wikimedia.org/show_bug.cgi?id=14210#c4

From #c5
"If that's the case those developers should ensure that token= is sent after
text=. "

/me looks how well documented that actually is

I changed the order and now, the token is the last property of the data-section.

http://commons.wikimedia.org/w/index.php?diff=55676627&oldid=55531162

But the error (502) still occurs.
In general it would be great to get something different than internal server error if it is an error at the client side (bad-formulated request ...)

If you need further information, don't hesitate to ask.

Being able to replicate it would be nice...

On commons, put

importScript("User:Rillke/AxUserMsg.js");

to your common.js or <skin>.js. I'm a trusted user there. I would not do something to harm someone's system, account or privacy.

Then go to my user-page

http://commons.wikimedia.org/wiki/User:Rillke

and try to add a template, by clicking "Notify this user" in the toolbar.
You will see that the template is added properly to my redirected discussion-page but server will return a 502-error.

Should I write a simple test-script?

(In reply to comment #10)

On commons, put

importScript("User:Rillke/AxUserMsg.js");

to your common.js or <skin>.js. I'm a trusted user there. I would not do
something to harm someone's system, account or privacy.

Then go to my user-page

http://commons.wikimedia.org/wiki/User:Rillke

and try to add a template, by clicking "Notify this user" in the toolbar.
You will see that the template is added properly to my redirected
discussion-page but server will return a 502-error.

Should I write a simple test-script?

If you could do a minimal use/test case to replicate it, that'd be really appreciated! :)

While trying to reproduce locally (on a 1.17wmf1 checkout. Cannot reproduce on trunk and on REL1_17 i get the JSON can't be converted to string error from up above).

Basically I get this in the apache error log:

[Mon Jun 20 18:47:57 2011] [notice] child pid 2018 exit signal Segmentation fault (11)

(and no response from the webserver)

Only seems to happen when following redirects (using redirect option) during action=edit.

Code I used to reproduce was (typed into a firebug console. Change paths/edit token as appropriate. Page Rd was a redirect to a page Foo :

var x = new XMLHttpRequest
x.open( 'POST', 'http://localhost/w/REL1_17/api.php?action=edit&appendtext=%0A%7B%7Bsubst%3APlease%20link%20images%7D%7D%0Atest~~~~%0A&format=json&summary=Please%20link%20images.&title=Rd&token=%2B%5C&watchlist=preferences&redirect=', false );
x.send();

Error I seem to get doing this locally...

"<?xml version=\"1.0\"?><api xmlns=\"http://www.mediawiki.org/xml/api/\" servedby=\"ubuntu64-esxi\"><error code=\"internal_api_error_MWException\" info=\"Exception Caught: Internal error in ApiFormatXml::recXmlPrint: (foo, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName().\" xml:space=\"preserve\">\n\n#0 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiBase.php(1205): wfDebugDieBacktrace('Internal error ...')\n#1 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiFormatXml.php(148): ApiBase::dieDebug('ApiFormatXml::r...', '(foo, ...) has ...')\n#2 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiFormatXml.php(163): ApiFormatXml::recXmlPrint('foo', Array, NULL)\n#3 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiFormatXml.php(73): ApiFormatXml::recXmlPrint('api', Array, NULL, false)\n#4 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(707): ApiFormatXml-&gt;execute()\n#5 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(683): ApiMain-&gt;printResult(false)\n#6 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(358): ApiMain-&gt;executeAction()\n#7 /home/reedy/mediawiki/trunk/phase3/includes/api/ApiMain.php(342): ApiMain-&gt;executeActionWithErrorHandling()\n#8 /home/reedy/mediawiki/trunk/phase3/api.php(121): ApiMain-&gt;execute()\n#9 {main}\n\n</error></api>"

[mid air collision, so this may repeat a little what Reedy said]
Further simplification of a minimal test case:

var x = new XMLHttpRequest
x.open( 'POST', 'http://localhost/w/REL1_17/api.php?action=edit&text=some_text&format=json&title=Rd&token=%2B%5C&redirect=', false );
x.send();

(With the page Rd being a redirect to some other page)

It seems to be some sort of recursive nesting issue in the result array. Well if the output format is json(fm), apache segfaults, the other formats throw exceptions:

dbg gives the following:

<b>Fatal error</b>: Nesting level too deep - recursive dependency? in <b>/var/www/w/REL1_17/includes/api/ApiFormatDbg.php</b> on line <b>50</b><br />

xml gives the following:

Exception Caught: Internal error in ApiFormatXml::recXmlPrint: (foo, ...) has integer keys without _element value. Use ApiResult::setIndexedTagName().

#0 /var/www/w/REL1_17/includes/api/ApiBase.php(1111): wfDebugDieBacktrace('Internal error ...')
#1 /var/www/w/REL1_17/includes/api/ApiFormatXml.php(140): ApiBase::dieDebug('ApiFormatXml::r...', '(foo, ...) has ...')
#2 /var/www/w/REL1_17/includes/api/ApiFormatXml.php(155): ApiFormatXml::recXmlPrint('foo', Array, NULL)
#3 /var/www/w/REL1_17/includes/api/ApiFormatXml.php(72): ApiFormatXml::recXmlPrint('api', Array, NULL, false)
[...rest of big long backtrace...]

Most interesting of all, the txt format gives me a var_dump of a Title object, which seems rather wrong. (I noticed on trunk, that the json format seems to output internal members of a Title object, which seems wrong. Maybe all thats changed between here and trunk is some magic ::toString stuff allowing json to print Title objects correctly). Anyways, outputting a title object seems rather wrong, and I'm going to guess that's where the trouble starts.

The fix is to remove a line that looks like a debugging line

Commit incoming

r90490

Merged to 1.17, tagged for 1.18, and merged r90490 into 1.17wmf1 in r90493

Will deploy