Created
January 25, 2015 19:23
-
-
Save olegwtf/849334dbc0499d41d1ee to your computer and use it in GitHub Desktop.
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
diff --git a/lib/Mojo/Server/Prefork.pm b/lib/Mojo/Server/Prefork.pm | |
index 1052111..96c33f5 100644 | |
--- a/lib/Mojo/Server/Prefork.pm | |
+++ b/lib/Mojo/Server/Prefork.pm | |
@@ -78,8 +78,12 @@ sub run { | |
local $SIG{INT} = local $SIG{TERM} = sub { $self->_term }; | |
local $SIG{CHLD} = sub { | |
while ((my $pid = waitpid -1, WNOHANG) > 0) { | |
- $self->app->log->debug("Worker $pid stopped.") | |
- if delete $self->emit(reap => $pid)->{pool}{$pid}; | |
+ if (my $w = delete $self->emit(reap => $pid)->{pool}{$pid}) { | |
+ $self->app->log->debug("Worker $pid stopped."); | |
+ unless ($w->{ok}) { | |
+ $self->workers($self->workers - 1); | |
+ } | |
+ } | |
} | |
}; | |
local $SIG{QUIT} = sub { $self->_term(1) }; | |
@@ -109,7 +113,7 @@ sub _heartbeat { | |
my $time = steady_time; | |
while ($chunk =~ /(\d+):(\d)\n/g) { | |
next unless my $w = $self->{pool}{$1}; | |
- $self->emit(heartbeat => $1) and $w->{time} = $time; | |
+ $self->emit(heartbeat => $1) and $w->{time} = $time and $w->{ok} = 1; | |
$w->{graceful} ||= $time if $2; | |
} | |
} | |
@@ -162,7 +166,7 @@ sub _spawn { | |
# Manager | |
die "Can't fork: $!" unless defined(my $pid = fork); | |
- return $self->emit(spawn => $pid)->{pool}{$pid} = {time => steady_time} | |
+ return $self->emit(spawn => $pid)->{pool}{$pid} = {time => steady_time, ok => 0} | |
if $pid; | |
# Prepare lock file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment