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

fix: ensure sleep KILL_OLD_DELAY #45

Merged
merged 2 commits into from
Oct 28, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Server/Starter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,9 @@ sub start_server {
my $kill_old_delay = defined $ENV{KILL_OLD_DELAY} ? $ENV{KILL_OLD_DELAY} : $ENV{ENABLE_AUTO_RESTART} ? 5 : 0;
if ($kill_old_delay != 0) {
print STDERR "sleeping $kill_old_delay secs before killing old workers\n";
sleep $kill_old_delay;
while ($kill_old_delay > 0) {
$kill_old_delay -= sleep $kill_old_delay;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you adjust the code so that $kill_old_delay will be decremented by one in case sleep returns zero?

My understanding is that the seconds returned by sleep is rounded down. And my fear that the loop might run forever if signals get delivered more than once a second.

Copy link
Contributor Author

@azrle azrle Oct 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be better, IMHO, to let $kill_old_delay be defined as the "lower bound" of sleep time to ensure new workers get ready to work. And in majority of cases, sleep should not be interrupted by continuous signals with interval < 1s.

However, I agree, it would be much safer to let it be the "upper bound". To avoid edge cases, I will round up the sleep time to at least one second. :)

}
}
print STDERR "killing old workers\n";
kill $opts->{signal_on_hup}, $_
Expand Down