Skip to content
Browse files

Attempt to handle re-exec failures gracefully on reload.

If re-execing ourself fails for some reason, soldier on, instead of
dieing and leaving detached children floating around.n
  • Loading branch information...
1 parent 7e9752d commit 356d254e3bd6290accd58ef1252c71a07d5dc7c9 @nelhage nelhage committed Jan 24, 2013
Showing with 14 additions and 12 deletions.
  1. +6 −3 lib/einhorn/command.rb
  2. +0 −3 lib/einhorn/command/interface.rb
  3. +8 −6 lib/einhorn/event.rb
View
9 lib/einhorn/command.rb
@@ -192,13 +192,16 @@ def self.reload
end
write.close
- Einhorn::Event.uninit
-
# Reload the original environment
ENV.clear
ENV.update(Einhorn::TransientState.environ)
- exec [Einhorn::TransientState.script_name, Einhorn::TransientState.script_name], *(['--with-state-fd', read.fileno.to_s, '--'] + Einhorn::State.cmd)
+ begin
+ exec [Einhorn::TransientState.script_name, Einhorn::TransientState.script_name], *(['--with-state-fd', read.fileno.to_s, '--'] + Einhorn::State.cmd)
+ rescue SystemCallError => e
+ Einhorn.log_error("Could not reload! Attempting to continue. Error was: #{e}")
+ read.close
+ end
end
def self.spinup(cmd=nil)
View
3 lib/einhorn/command/interface.rb
@@ -292,9 +292,6 @@ def self.unrecognized_command(conn, request)
# buffer and lost upon reload.
send_message(conn, 'Reloading, as commanded')
Einhorn::Command.reload
-
- # Reload should not return
- raise "Not reachable"
end
command 'inc', 'Increment the number of Einhorn child processes' do
View
14 lib/einhorn/event.rb
@@ -8,20 +8,22 @@ module Event
@@writeable = {}
@@timers = {}
+ def self.cloexec!(fd)
+ fd.fcntl(Fcntl::F_SETFD, fd.fcntl(Fcntl::F_GETFD) | Fcntl::FD_CLOEXEC)
+ end
+
def self.init
readable, writeable = IO.pipe
@@loopbreak_reader = LoopBreaker.open(readable)
@@loopbreak_writer = writeable
- end
- def self.uninit
- # These don't need to persist across Einhorn reloads, so let's not keep.
- @@loopbreak_reader.close
- @@loopbreak_writer.close
+ cloexec!(readable)
+ cloexec!(writeable)
end
def self.close_all
- uninit
+ @@loopbreak_reader.close
+ @@loopbreak_writer.close
(@@readable.values + @@writeable.values).each do |descriptors|
descriptors.each do |descriptor|
descriptor.close

0 comments on commit 356d254

Please sign in to comment.
Something went wrong with that request. Please try again.