From 29003f2e3d7a1246eb61d740981cc162b8e835f8 Mon Sep 17 00:00:00 2001 From: Andreas Fuchs Date: Sat, 2 Mar 2013 21:11:45 -0800 Subject: [PATCH] Kill the zeusclient only if something went wrong Previously, the runner would kill the client process at_exit - this introduced a race condition where the client would sometimes get the async TERM signal before it could read the exit status, and exit with a failure status. While the reasoning behind killing the client is sound (if the runner dies without the client noticing, the client could hang around forever), it should only happen if there's an exceptional condition. --- rubygem/lib/zeus.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rubygem/lib/zeus.rb b/rubygem/lib/zeus.rb index 32715fa0..d032c005 100644 --- a/rubygem/lib/zeus.rb +++ b/rubygem/lib/zeus.rb @@ -118,14 +118,17 @@ def command(identifier, sock) kill_command_if_client_quits!(pid, client_pid) - at_exit{ Process.kill(:TERM, client_pid) } - Process.wait(pid) code = $?.exitstatus || 0 local.write "#{code}\0" local.close + rescue Exception + # If anything at all went wrong, kill the client - if anything + # went wrong before the runner can clean up, it might hang + # around forever. + Process.kill(:TERM, client_pid) end def kill_command_if_client_quits!(command_pid, client_pid)