about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-01-17 02:03:04 +0000
committerEric Wong <normalperson@yhbt.net>2014-01-17 08:34:29 +0000
commit3e701ee74ff29bdf5daa3249acede5a85a2b0097 (patch)
tree176888175c2b975f9a1ac1a33f0452e6b3d3bf86
parent1b3e68e3eac0c3fbb2a32e4fddd26ee8a50ec627 (diff)
downloadrainbows-3e701ee74ff29bdf5daa3249acede5a85a2b0097.tar.gz
Internal reworking of unicorn 4.8.0 completely broke us(!).
This commit fixes things, but it means we no longer support
unicorn <= 4.7.  Sorry about that.
-rw-r--r--lib/rainbows.rb5
-rw-r--r--lib/rainbows/base.rb19
-rw-r--r--rainbows.gemspec5
-rw-r--r--t/test_isolate.rb12
4 files changed, 27 insertions, 14 deletions
diff --git a/lib/rainbows.rb b/lib/rainbows.rb
index bfa1ba0..82a8448 100644
--- a/lib/rainbows.rb
+++ b/lib/rainbows.rb
@@ -55,6 +55,7 @@ module Rainbows
     attr_reader :alive
     attr_writer :worker
     attr_writer :forked
+    attr_writer :readers
   end
 
   def self.config!(mod, *opts)
@@ -88,7 +89,9 @@ module Rainbows
       @alive = false
       Rainbows::HttpParser.quit
       @expire = Time.now + (@server.timeout * 2.0)
-      Unicorn::HttpServer::LISTENERS.each { |s| s.close rescue nil }.clear
+      tmp = @readers.dup
+      @readers.clear
+      tmp.each { |s| s.close rescue nil }.clear
       @at_quit.each { |task| task.call }
     end
     false
diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb
index 54f1d2d..a7ba17d 100644
--- a/lib/rainbows/base.rb
+++ b/lib/rainbows/base.rb
@@ -8,24 +8,33 @@
 module Rainbows::Base
   # :stopdoc:
 
+  def sig_receiver(worker)
+    begin
+      worker.to_io.kgio_wait_readable
+      worker.kgio_tryaccept # Unicorn::Worker#kgio_tryaccept
+    rescue => e
+      Rainbows.alive or return
+      Unicorn.log_error(Rainbows.server.logger, "signal receiver", e)
+    end while true
+  end
+
   # this method is called by all current concurrency models
   def init_worker_process(worker) # :nodoc:
-    super(worker)
+    readers = super(worker)
     Rainbows::Response.setup
     Rainbows::MaxBody.setup
     Rainbows.worker = worker
 
-    # we're don't use the self-pipe mechanism in the Rainbows! worker
-    # since we don't defer reopening logs
-    Rainbows::HttpServer::SELF_PIPE.each { |x| x.close }.clear
-
     # spawn Threads since Logger takes a mutex by default and
     # we can't safely lock a mutex in a signal handler
     trap(:USR1) { Thread.new { reopen_worker_logs(worker.nr) } }
     trap(:QUIT) { Thread.new { Rainbows.quit! } }
     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
     Rainbows::ProcessClient.const_set(:APP, Rainbows.server.app)
+    Thread.new { sig_receiver(worker) }
     logger.info "Rainbows! #@use worker_connections=#@worker_connections"
+    Rainbows.readers = readers # for Rainbows.quit
+    readers # unicorn 4.8+ needs this
   end
 
   def process_client(client)
diff --git a/rainbows.gemspec b/rainbows.gemspec
index 2ef91f7..e55c7de 100644
--- a/rainbows.gemspec
+++ b/rainbows.gemspec
@@ -28,8 +28,9 @@ Gem::Specification.new do |s|
   s.add_dependency(%q<kgio>, ['~> 2.5'])
 
   # we need Unicorn for the HTTP parser and process management
-  # 4.6.0+ supports hijacking, 4.6.2 fixes the chunk parser (for Ruby 2.0.0)
-  s.add_dependency(%q<unicorn>, ["~> 4.6", ">= 4.6.2"])
+  # we need unicorn 4.8.0+ since we depend on undocumented/unsupported
+  # unicorn internals.
+  s.add_dependency(%q<unicorn>, ["~> 4.8"])
 
   s.add_development_dependency(%q<isolate>, "~> 3.1")
   s.add_development_dependency(%q<wrongdoc>, "~> 1.6")
diff --git a/t/test_isolate.rb b/t/test_isolate.rb
index f5f97b1..8f701ab 100644
--- a/t/test_isolate.rb
+++ b/t/test_isolate.rb
@@ -16,14 +16,14 @@ $stdout.reopen($stderr)
 lock = File.open(__FILE__, "rb")
 lock.flock(File::LOCK_EX)
 Isolate.now!(opts) do
-  gem 'kgio', '2.8.0'
+  gem 'kgio', '2.8.1'
   gem 'rack', '1.5.2'
   gem 'kcar', '0.4.0'
-  gem 'raindrops', '0.11.0'
-  gem 'unicorn', '4.6.2'
+  gem 'raindrops', '0.12.0'
+  gem 'unicorn', '4.8.0'
 
   if engine == "ruby"
-    gem 'sendfile', '1.1.0'
+    gem 'sendfile', '1.2.1'
     gem 'cool.io', '1.1.0'
 
     gem 'eventmachine', '1.0.0'
@@ -39,10 +39,10 @@ Isolate.now!(opts) do
   end
 
   if RUBY_PLATFORM =~ /linux/
-    gem 'sleepy_penguin', '3.1.0'
+    gem 'sleepy_penguin', '3.3.0'
 
     # is 2.6.32 new enough?
-    gem 'io_splice', '4.1.1' if `uname -r`.strip > '2.6.32'
+    gem 'io_splice', '4.2.0' if `uname -r`.strip > '2.6.32'
   end
 end