Skip to content

Commit 2074be8

Browse files
committed
Correctly detect PHP fatal errors
1 parent 13f74c4 commit 2074be8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/AsyncTask.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class AsyncTask
6666
*/
6767
private const TIME_EPSILON = 0.1;
6868

69+
/**
70+
* The bitmask that can filter for fatal runtime errors.
71+
*
72+
* Fatal errors other than the specific "time limit exceeded" error must not trigger the timeout handlers.
73+
*/
74+
private const FATAL_ERROR_BITMASK = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR;
75+
6976
/**
7077
* Indicates whether GNU coreutils is found in the system; in particular, we are looking for the timeout command inside coreutils.
7178
*
@@ -314,7 +321,7 @@ private function hasTimedOut(): bool
314321
// runtime timeout triggers a PHP fatal error
315322
// this can happen on Windows by our specification, or on Unix when the actual CLI PHP time limit is smaller than the time limit of this task
316323
$lastError = error_get_last();
317-
if ($lastError !== null) {
324+
if ($lastError !== null && ($lastError['type'] & self::FATAL_ERROR_BITMASK)) {
318325
// has fatal error; is it our timeout error?
319326
fwrite(STDERR, "error_get_last " . json_encode($lastError) . PHP_EOL);
320327
return str_contains($lastError['message'], "Maximum execution time");

0 commit comments

Comments
 (0)