-
-
Notifications
You must be signed in to change notification settings - Fork 257
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
Allow signal handling for Uv w/o 100% cpu usage #330
base: 2.x
Are you sure you want to change the base?
Conversation
Not a very good solution imo. Now the signal handler can't control the exit code. |
examples/event-loop/signals.php
Outdated
Loop::onSignal(SIGINT, function () { | ||
print "Caught SIGINT, exiting..." . PHP_EOL; | ||
|
||
// Check for a Uv driver | ||
if (Loop::get() instanceof Amp\Loop\UvDriver) { | ||
|
||
// Stop the loop | ||
Loop::stop(); | ||
|
||
// Cannot exit out of a UvDriver loop here, can only stop the loop | ||
return; | ||
} | ||
|
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.
What happens if you cancel the signal watcher before existing? Did you look where exactly it hangs in probably an infinite loop causing the 100% CPU usage?
Loop::onSignal(SIGINT, function () { | |
print "Caught SIGINT, exiting..." . PHP_EOL; | |
// Check for a Uv driver | |
if (Loop::get() instanceof Amp\Loop\UvDriver) { | |
// Stop the loop | |
Loop::stop(); | |
// Cannot exit out of a UvDriver loop here, can only stop the loop | |
return; | |
} | |
Loop::onSignal(SIGINT, function ($watcherId) { | |
print "Caught SIGINT, exiting..." . PHP_EOL; | |
Loop::cancel($watcherId); | |
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.
Not sure where my comment ended up, so sorry if this is a double tap.
Just tried this code and it still seems to get stuck in a loop. I tried debugging it for a couple hours, but I didn't get anywhere. Xdebug seemed to dump the profiler data before it got stuck in the loop, which made me think it was a Uv
lib problem. (trying without xdebug loaded results in the same problem)
Hmm, looks like it still gets stuck in the loop. I tried for a couple hours to find where the loop occurs, but I didn't get anywhere. It seemed as if it was happening in due to the libuv module (it was happening after the xdebug profiler closed out). Co-authored-by: Niklas Keller <[email protected]>
I can't reproduce 100% CPU usage, but I get a warning:
|
Using |
Please try with the latest |
Alright, give me a hot minute to try it. PS: Thanks for being so active, you guys are awesome. |
No luck. Same result. I'm not sure this is worth putting too much work into unless someone else runs into the same issue. They can reference this conversation. |
Which PHP version do you use? |
Using the following:
If I switch from |
Perhaps there's an issue in |
Ref #329
To be honest this could lend itself to its own
Uv
specific example file, but here's something that could work regardless of driver used.Again, downside is that the end of code execution is not in the signal handling function, but sometime after the
Loop::run()
line.