unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: mongrel-unicorn@rubyforge.org
Subject: [PATCH] avoid race condition during worker startup
Date: Sat, 1 Feb 2014 20:28:40 +0000	[thread overview]
Message-ID: <20140201202840.GA12609@dcvr.yhbt.net> (raw)

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.
---
  gem install --pre -v 4.8.1.1.g9b565 unicorn

 lib/unicorn/http_server.rb | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 2052d53..21cb9a1 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
@@ -120,6 +120,7 @@ class Unicorn::HttpServer
     # 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 @@ class Unicorn::HttpServer
     # 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 @@ class Unicorn::HttpServer
   end
 
   def awaken_master
+    return if $$ != @master_pid
     SELF_PIPE[1].kgio_trywrite('.') # wakeup master process from select
   end
 
-- 
1.8.5.3.368.gab0bcec

-- 
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying

                 reply	other threads:[~2014-02-01 20:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/unicorn/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140201202840.GA12609@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=mongrel-unicorn@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/unicorn.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).