# HG changeset patch # User Sergey Kandaurov # Date 1640806163 -10800 # Node ID ba6e24e38f036a4ca35e91430afabdd0420788d1 # Parent 18ac4d9e5a2af23dea199e668688e17feda38352 Tests: improved stop_daemons() to send signal again. As was observed, it's possible that a signal to complete a uwsgi daemon can be ignored while it is starting up, which results in tests hang due to eternal waiting on child processes termination. Notably, it is seen when running tests with a high number of prove jobs on a low-profile VM against nginx with broken modules and/or configuration. To reproduce: $ TEST_NGINX_GLOBALS=ERROR prove -j16 uwsgi*.t Inspecting uwsgi under ktrace on FreeBSD confirms that a SIGTERM signal is ignored at the very beginning of uwsgi startup. It is then replaced with a default action after listen(), thus waiting until uwsgi is ready to accept new TCP connections doesn't completely solve the hang window. The fix is to retry sending a signal some time after waitpid(WNOHANG) continuously demonstrated no progress with reaping a signaled process. It is modelled after f13ead27f89c that improved stop() for nginx. diff --git a/lib/Test/Nginx.pm b/lib/Test/Nginx.pm --- a/lib/Test/Nginx.pm +++ b/lib/Test/Nginx.pm @@ -554,7 +554,19 @@ sub stop_daemons() { while ($self->{_daemons} && scalar @{$self->{_daemons}}) { my $p = shift @{$self->{_daemons}}; kill $^O eq 'MSWin32' ? 9 : 'TERM', $p; - waitpid($p, 0); + + my $exited; + + for (1 .. 50) { + $exited = waitpid($p, WNOHANG) != 0; + last if $exited; + select undef, undef, undef, 0.1; + } + + if (!$exited) { + kill $^O eq 'MSWin32' ? 9 : 'TERM', $p; + waitpid($p, 0); + } } return $self;