Page MenuHomePhabricator

Maintenance scripts exit with 0 when an (uncaught) exception is encountered
Closed, ResolvedPublic

Description

Maintenance scripts exit with 0 when they fail due to an exception, as I just discovered on the snapshot hosts (Wikidata dumps failed there, but exited with 0).

Can be easily reproduced: Take any maintenance script and put throw new \Exception(); at the top of its execute function (I tested it with maintenance/refreshLinks.php but any script should work). It will exit with 0 (success).

This happens as MW sets its own exception handler (set_exception_handler):

$ cat test.php 
<?php

throw new Exception();

echo 1;
$ php test.php 
PHP Fatal error:  Uncaught Exception in /home/hoch_m/tmp/test.php:5
Stack trace:
#0 {main}
  thrown in /home/hoch_m/tmp/test.php on line 5
$ echo $?
255

but once we add an exception handler:

$ cat test.php 
<?php

set_exception_handler(function($e) {echo "ACK\n";});

throw new Exception();

echo 1;
$ php test.php 
ACK
$ echo $?
0

Event Timeline

hoo created this task.Oct 4 2017, 3:59 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptOct 4 2017, 3:59 PM

Change 382181 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/core@master] CLI: Make sure we don't exit with 0 when an exception is encountered

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

Change 382181 merged by jenkins-bot:
[mediawiki/core@master] CLI: Make sure we don't exit with 0 when an exception is encountered

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

hoo closed this task as Resolved.Oct 5 2017, 8:51 AM
hoo claimed this task.
hoo removed a project: Patch-For-Review.
Krinkle added a subscriber: Krinkle.Oct 6 2017, 7:34 PM

This explains why postgres was seemingly passing on Travis CI when in fact it was broken (again).