-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Respect script execution time limit when invoking shutdown functions #5543
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--TEST-- | ||
Async signals in zend_call_function | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded("pcntl")) print "skip"; | ||
if (getenv("SKIP_SLOW_TESTS")) print "skip slow test"; | ||
?> | ||
--FILE-- | ||
<?php | ||
|
||
pcntl_async_signals(1); | ||
pcntl_signal(SIGALRM, function($signo) { | ||
throw new Exception("Alarm!"); | ||
}); | ||
|
||
pcntl_alarm(1); | ||
try { | ||
array_map( | ||
'time_nanosleep', | ||
array_fill(0, 360, 1), | ||
array_fill(0, 360, 0) | ||
); | ||
} catch (Exception $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
Alarm! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about this a bit, I think instead of checking timed_out specifically here, we should do a VM interrupt check as in
php-src/Zend/zend_vm_def.h
Line 9206 in 5d93eab
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I think I have figured out what you mean...
pcntl
sets a signal handler which setsvm_interrupt
to 1. That causes execution to bounce intopcntl
'szend_interrupt_function
next time the VM checks the interrupt flag. But that only happens when the VM is running PHP bytecode.If you are running native shutdown functions, and
pcntl
is enabled, and a signal comes along, it will set thevm_interrupt
flag butpcntl
'szend_interrupt_function
will never be called.Do you think
pcntl
really should care about what is happening during shutdown, though? Maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During shutdown probably isn't important, but there are other cases where we could run into this, at least in theory. For example, consider something like
array_map('expensive_internal_function', $array)
. This would allow a signal handler to be executed in the middle of the array_map, rather than at the end.Maybe it's possible to test this with a combination of
InfiniteIterator
anditerator_apply
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha. Wow, I never thought of that. OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an extra test in 7f35610. I was hoping to show that this leaks the time_nanosleep return value (which should be an array in this case), but due to the way array_map is implemented this doesn't happen...
I think we should be repeating the
EG(exception)
check from a few lines above if the VM interrupt is executed, to make sure that code not freeing the retval on exception doesn't leak...