From 27055204962177972df0f996af4d8b88e4577526 Mon Sep 17 00:00:00 2001 From: David Dollar Date: Sun, 29 Jan 2012 00:09:28 -0500 Subject: [PATCH] fix race condition with process termination --- lib/foreman/engine.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/foreman/engine.rb b/lib/foreman/engine.rb index 089f597..ff23126 100644 --- a/lib/foreman/engine.rb +++ b/lib/foreman/engine.rb @@ -78,9 +78,17 @@ private ###################################################################### end def terminate_gracefully + return if @terminating + @terminating = true info "sending SIGTERM to all processes" kill_all "SIGTERM" - Timeout.timeout(5) { Process.waitall } + Timeout.timeout(5) do + while running_processes.length > 0 + pid, status = Process.wait2 + process = running_processes.delete(pid) + info "process terminated", process.name + end + end rescue Timeout::Error info "sending SIGKILL to all processes" kill_all "SIGKILL" @@ -112,7 +120,6 @@ private ###################################################################### process = running_processes.delete(pid) info "process terminated", process.name terminate_gracefully - kill_all rescue Errno::ECHILD end