Execute signal handlers before restarting syscalls#22538
Draft
arnaud-lb wants to merge 13 commits into
Draft
Conversation
Member
|
This is a pretty reasonable proposal and I will support this. Thank you for picking this up. |
…) fails with non-EINTR
This makes it possible to interrupt syscalls performed by signal handlers. Refactor the queue to a ring buffer as it's more concurrency friendly.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PoCs the ideas discussed in #5521:
Syscalls are interrupted when:
SignalResult::InterruptSignalResult::Defaultor no value, and was registered with$restart_syscall=falseEG(timed_out)is setOtherwise, syscalls are restarted.
Implemented only in
php_sockop_*for now, but the goal would be to implement this for all syscalls eventually, and at least for existing EINTR loops. (Edit: Since we are clearing SA_RESTART now, syscalls that would be restarted by the OS before are not restarted anymore. So we may have to implement restarting for all syscalls immediately.)API changes:
New enum:
pcntl_signal() changes: The $handler function must now return a
SignalReturn,NULL, or no value. Before, the return value was ignored.Some considerations:
Exceptions vs return value:
Returning a value is more PHP-ish than throwing an exception, but exceptions have some benefits in this context:
SignalResult::Interruptfrom a handler does nothing outside of syscallsBC breaks:
NULLorSignalResultfrom a signal handler will throw aTypeErrorDemo:
If a SIGINT (Ctrl-C) is delivered during the fread() call, the signal handler is executed immediately to decide whether the syscall should be restarted or not. In this case the handler decides to not restart, so the fread() call returns.
Previously, the signal would be queued and fread() would hang indefinitely.
TODO: