Permalink
Browse files

avoid race condition during worker startup

We close SELF_PIPE in the worker immediately, but signal handlers
do not get setup immediately.  So prevent workers from erroring out
due to invalid SELF_PIPE.
  • Loading branch information...
1 parent cce86f5 commit 9b565f1808a16bc63e9e15e2cbe77d947c502706 Eric Wong committed Feb 1, 2014
Showing with 2 additions and 1 deletion.
  1. +2 −1 lib/unicorn/http_server.rb
@@ -120,6 +120,7 @@ def start
# this pipe is used to wake us up from select(2) in #join when signals
# are trapped. See trap_deferred.
SELF_PIPE.replace(Unicorn.pipe)
+ @master_pid = $$
# setup signal handlers before writing pid file in case people get
# trigger happy and send signals as soon as the pid file exists.
@@ -133,7 +134,6 @@ def start
# we upgrade and the upgrade breaks during preload_app==true && build_app!
self.pid = config[:pid]
- self.master_pid = $$
build_app! if preload_app
bind_new_listeners!
@@ -390,6 +390,7 @@ def master_sleep(sec)
end
def awaken_master
+ return if $$ != @master_pid
SELF_PIPE[1].kgio_trywrite('.') # wakeup master process from select
end

0 comments on commit 9b565f1

Please sign in to comment.