Skip to content

Commit

Permalink
Cleanup state for children that die during reexec
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-stripe committed Sep 9, 2014
1 parent 0f53180 commit dad306b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions lib/einhorn.rb
Expand Up @@ -130,11 +130,29 @@ def self.update_state(store, store_name, old_state)
message << "upgraded :reloading_for_preload_upgrade to :reloading_for_upgrade"
end

# For a period, we created children entries for state_passers,
# but we don't want that (in particular, it probably died before
# we could setup our SIGCHLD handler
if updated_state[:children]
# For a period, we created children entries for state_passers,
# but we don't want that (in particular, it probably died
# before we could setup our SIGCHLD handler
updated_state[:children].delete_if {|k, v| v[:type] == :state_passer}

# Depending on what is passed for --reexec-as, it's possible
# that the process received a SIGCHLD while something other
# than einhorn was the active executable. If that happened,
# einhorn might not know about a dead child, so let's check
# them all
dead = []
updated_state[:children].each do |pid, v|
begin
pid = Process.wait(pid, Process::WNOHANG)
dead << pid if pid
rescue Errno::ECHILD
dead << pid
end
end
Einhorn::Event::Timer.open(0) do
dead.each {|pid| Einhorn::Command.mourn(pid)}
end
end
end

Expand Down

0 comments on commit dad306b

Please sign in to comment.