Repository navigation
Throw UnwindExit on timeout #25187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Throw UnwindExit on timeout #25187
Changes from all commits
6b0e7c5
80aff09
a960274
5b07a21
eb187e0
1b343f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1494,7 +1494,8 @@ ZEND_API zend_result zend_eval_string_ex(const char *str, zval *retval_ptr, cons | |
|
|
||
| static void zend_set_timeout_ex(zend_long seconds, bool reset_signals); | ||
|
|
||
| ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */ | ||
| /* zend_timeout() is called by the VM interrupt handler or by zend_call_function() when EG(timed_out) is set */ | ||
| ZEND_API ZEND_COLD void ZEND_FASTCALL zend_timeout(void) /* {{{ */ | ||
| { | ||
| #if defined(PHP_WIN32) | ||
| # ifndef ZTS | ||
|
|
@@ -1514,7 +1515,25 @@ ZEND_NORETURN ZEND_API void ZEND_FASTCALL zend_timeout(void) /* {{{ */ | |
| zend_set_timeout_ex(0, true); | ||
| #endif | ||
|
|
||
| zend_error_noreturn(E_ERROR, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s"); | ||
| /* Trigger error but do not bail */ | ||
| zend_error(E_ERROR | E_DONT_BAIL, "Maximum execution time of " ZEND_LONG_FMT " second%s exceeded", EG(timeout_seconds), EG(timeout_seconds) == 1 ? "" : "s"); | ||
|
|
||
| /* Do not call destructors */ | ||
| zend_objects_store_mark_destructed(&EG(objects_store)); | ||
|
|
||
| /* Exception has been handled by zend_error() */ | ||
| ZEND_ASSERT(!EG(exception)); | ||
|
|
||
| EG(exception) = zend_create_unwind_exit(); | ||
|
|
||
| zend_execute_data *execute_data = EG(current_execute_data); | ||
| if (execute_data | ||
| && execute_data->func | ||
| && ZEND_USER_CODE(execute_data->func->common.type) | ||
| && execute_data->opline->opcode != ZEND_HANDLE_EXCEPTION) { | ||
| EG(opline_before_exception) = EG(current_execute_data)->opline; | ||
|
arnaud-lb marked this conversation as resolved.
Resolved
|
||
| EG(current_execute_data)->opline = EG(exception_op); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This duplicates |
||
| } | ||
| /* }}} */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10743,6 +10743,7 @@ ZEND_VM_HELPER(zend_interrupt_helper, ANY, ANY) | |
| #endif | ||
| if (atomic_load(&EG(timed_out))) { | ||
| zend_timeout(); | ||
| HANDLE_EXCEPTION(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } else if (ZEND_HAS_OOM()) { | ||
| zend_handle_delayed_oom(); | ||
| HANDLE_EXCEPTION(); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
| Timeout within shutdown function, user function variation | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
| ?> | ||
| --INI-- | ||
| max_execution_time=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| register_shutdown_function(function () { | ||
| while (true) {} | ||
| }); | ||
| register_shutdown_function(function () { | ||
| echo "Not executed\n"; | ||
| while (true) {} | ||
| }); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Maximum execution time of 1 second exceeded in %stimeout_variation_11.php on line %d |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --TEST-- | ||
| Timeout does not call destructors | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
| ?> | ||
| --INI-- | ||
| max_execution_time=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $obj = new class { | ||
| function __destruct() { | ||
| echo "destructor called\n"; | ||
| } | ||
| }; | ||
|
|
||
| register_shutdown_function(function() { | ||
| echo "shutdown function called\n"; | ||
| }); | ||
|
|
||
| while (true) {} | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Maximum execution time of 1 second exceeded in %stimeout_variation_12.php on line %d | ||
| shutdown function called |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| --TEST-- | ||
| Timeout does not execute finally blocks | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
| ?> | ||
| --INI-- | ||
| max_execution_time=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $gen1 = (function () { | ||
| try { | ||
| yield; | ||
| } finally { | ||
| echo "finally executed (1)\n"; | ||
| } | ||
| })(); | ||
| $gen1->current(); | ||
|
|
||
| $gen2 = (function () { | ||
| try { | ||
| while (true) {} | ||
| } finally { | ||
| echo "finally executed (2)\n"; | ||
| } | ||
| yield; | ||
| })(); | ||
|
|
||
| try { | ||
| foreach ($gen2 as $value) {} | ||
| } finally { | ||
| echo "finally executed (3)\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Maximum execution time of 1 second exceeded in %stimeout_variation_13.php on line %d |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --TEST-- | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs |
||
| Timeout within internal function | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
| ?> | ||
| --INI-- | ||
| max_execution_time=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| zend_test_timeout(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Fatal error: Maximum execution time of 1 second exceeded in %stimeout_variation_14.php on line 3 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --TEST-- | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs |
||
| Timeout while EG(exception) is already set | ||
| --SKIPIF-- | ||
| <?php | ||
| if (getenv("SKIP_SLOW_TESTS")) die("skip slow test"); | ||
| ?> | ||
| --INI-- | ||
| max_execution_time=1 | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| zend_test_timeout_throw(); | ||
|
|
||
| ?> | ||
| --EXPECTF-- | ||
| Warning: Uncaught Exception: Timeout in %s:%d | ||
| Stack trace: | ||
| #0 %s(%d): zend_test_timeout_throw() | ||
| #1 {main} | ||
| thrown in %s on line %d | ||
|
|
||
| Fatal error: Maximum execution time of 1 second exceeded in %stimeout_variation_15.php on line 3 | ||
Uh oh!
There was an error while loading. Please reload this page.