Subject: | parent-process is exited without waiting for child process to be finished |
(Sorry, my English is poor.)
In any fork type servers, parent-process is exited without waiting for
child process to be finished.
In close_children()
-----------
1 while waitpid(-1, POSIX::WNOHANG()) > 0;
-----------
This code get the signal from finished child process, but it ignores the
child process which is executing.
The job that wants not to be stopped before completion will catch TERM.
For example, dequeue which handles the queue. Or job that wants to be
over after completely saving the data of one lump.
These children do not stop by TERM immediately, but parent-process think
that children finished. And server closes. Or server may restart.
Simplest solution.
-----------
sub post_child_cleanup_hook { 1 until waitpid(-1, POSIX::WNOHANG()) == -1; }
-----------
However, this does not consider HUP. Therefore, there is it as follows.
-----------
sub pre_server_close_hook { 1 until waitpid(-1, POSIX::WNOHANG()) == -1; }
-----------
However, we cannot know server-close-processing was started by log
because it is executed before "Server closing" was written to log.
I think that it may not be an important problem that HUP is not considered.
Best solution.
-----------
sub close_children {
my $self = shift;
$self->SUPER::close_children;
1 until waitpid(-1, POSIX::WNOHANG()) == -1;
}
-----------
This is executed only when there is child process.