Skip to content
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

Open
wants to merge 2 commits into
base: 2.x
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/event-loop/signals.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,20 @@

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;
}

Copy link
Member

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?

Suggested change
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);

Copy link
Author

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)

exit(0);
});

Loop::run();

exit(0);