Antony Gelberg | 29 Jan 14:06 2015

Timeouts longer than expected.

Hi all.  We use unicorn in production across four servers, behind
nginx and HAProxy (to load balance).  We set a 300s timeout in the
config file.  On an average day, we see something like:

E, [2015-01-22T17:01:24.335600 #4311] ERROR -- : worker=2 PID:21101
timeout (301s > 300s), killing

in our logs, ~60 times.  However, one day we noticed that production
had gone down with all the unicorns showing entries like the

E, [2015-01-22T12:35:15.643020 #4311] ERROR -- : worker=1 PID:4605
timeout (451s > 300s), killing

(note the 451s before it was killed).

Any clues how we can better-understand the root cause, even if it's
something we'll put in place for the future?  We lack visibility here.

Thanks in advance,


Eric Wong | 28 Jan 19:44 2015

[PATCH] http: -Wshorten-64-to-32 warnings on clang

Tested on x86_64, clang version 3.5-1ubuntu1 (trunk) (LLVM 3.5)
These warnings were introduced on
commit 4b2782a926d8f131b1e7382be35e3abb77bf4be5
("http: reduce parser from 72 to 56 bytes on 64-bit")
and did not affect any releases.

These length checks should not be necessary in reality because
HTTP header sizes never come close to 4GB in size.

Fixup a minor coding style (inherited from Mongrel) violation
while we're at it (tabs => spaces).
 ext/unicorn_http/unicorn_http.rl | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 3294357..de83652 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
 <at>  <at>  -69,13 +69,25  <at>  <at>  static void parser_raise(VALUE klass, const char *msg)
   VALUE exc = rb_exc_new2(klass, msg);
   VALUE bt = rb_ary_new();

-	rb_funcall(exc, id_set_backtrace, 1, bt);
-	rb_exc_raise(exc);
+  rb_funcall(exc, id_set_backtrace, 1, bt);
+  rb_exc_raise(exc);
+static inline unsigned int ulong2uint(unsigned long n)
(Continue reading)

Joe Williams | 23 Jan 19:32 2015

global variable in after_fork

I am attempting to do something like the following:

after_fork do |server, worker|
  $unicorn_uptime =

Unfortunately the variable comes up nil when later accessed. Anyone have
thoughts on what I am missing?


Eric Wong | 22 Jan 06:12 2015

[RFC] remove old inetd+git examples and exec_cgi

I'm tempted to remove these for 5.x, but maybe somebody depends on the
lib/unicorn/app/* portions somewhere... Does anybody care?

Subject: [PATCH] remove old inetd+git examples and exec_cgi

While it was technically interesting and fun to tunnel arbitrary
protocols over a semi-compliant Rack interface, nobody actually does
it (and anybody who does can look in our git history).  This was
from back in 2009 when this was one of the few servers that could
handle chunked uploads, nowadays everyone does it! (or do they? :)

A newer version of exec_cgi.rb still lives on in the repository of
yet another horribly-named server, but there's no point in bloating
the installation footprint of somewhat popular server such as unicorn.
 examples/             |  13 ----
 lib/unicorn/app/exec_cgi.rb | 154 --------------------------------------------
 lib/unicorn/app/inetd.rb    | 109 -------------------------------
 3 files changed, 276 deletions(-)
 delete mode 100644 examples/
 delete mode 100644 lib/unicorn/app/exec_cgi.rb
 delete mode 100644 lib/unicorn/app/inetd.rb


Eric Wong | 18 Jan 04:39 2015

[PATCH] use the monotonic clock under Ruby 2.1+

The monotonic clock is immune to time adjustments so it is not
thrown off by misconfigured clocks.  Process.clock_gettime also
generates less garbage on 64-bit systems due to the use of Flonum.
 lib/unicorn/http_server.rb | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index a523fce..e0c0370 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
 <at>  <at>  -265,7 +265,7  <at>  <at>  class Unicorn::HttpServer
   # is signalling us too often.
   def join
     respawn = true
-    last_check =
+    last_check = time_now

     proc_name 'master' "master process ready" # test_exec.rb relies on this message
 <at>  <at>  -283,7 +283,7  <at>  <at>  class Unicorn::HttpServer
       when nil
         # avoid murdering workers after our master process (or the
         # machine) comes out of suspend/hibernation
-        if (last_check +  <at> timeout) >= (last_check =
+        if (last_check +  <at> timeout) >= (last_check = time_now)
           sleep_time = murder_lazy_workers
           sleep_time =  <at> timeout/2.0 + 1
 <at>  <at>  -337,8 +337,8  <at>  <at>  class Unicorn::HttpServer
(Continue reading)

Eric Wong | 10 Jan 05:49 2015

[PUSHED] switch docs + website to olddoc

wrongdoc was difficult to maintain because of the tidy-ffi
dependency and the HTML5 changes in Darkfish could not be
handled well by Tidy.

olddoc is superior as it generates leaner HTML which loads faster,
requires less scrolling and less processing power to render.
Aesthetic comparisons are subjective of course but completely
unimportant compared to speed and accessibility.

The presence of images and CSS on the old (Darkfish-based) site
probably set unreasonable expectations as to my ability and
willingness to view such things.  No more, the new website is
entirely simple HTML which renders well with even the wimpiest

Eric Wong | 10 Jan 05:46 2015

[PATCH] README: clarify/reduce references to unicorn_rails

unicorn_rails is an ancient compatibility wrapper for ancient
versions of Rails which did not use Rack.  Those applications have
likely moved on, so stop promoting unicorn_rails.
 README | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/README b/README
index 1bd42b8..02d01e1 100644
--- a/README
+++ b/README
 <at>  <at>  -95,13 +95,13  <at>  <at>  from git.

 == Usage

-=== non-Rails Rack applications
+=== Rack (including Rails 3+) applications

 In APP_ROOT, run:


-=== for Rails applications (should work for all 1.2 or later versions)
+=== Ancient Rails 1.2 - 2.x versions

 In RAILS_ROOT, run:

 <at>  <at>  -122,8 +122,7  <at>  <at>  The default settings are designed for maximum out-of-the-box
 compatibility with existing applications.

(Continue reading)

Aaron Price | 30 Dec 17:38 2014

Unicorn workers timing out intermittently

Hey guys,

I'm having the following issue and I was hoping you might be able to shed
some light on the issue. Maybe give some suggestions on how to debug the
actual problem.

Any help is appreciated.



Eric Wong | 28 Dec 08:06 2014

Re: [RFC] http: TypedData C-API conversion

Eric Wong <e <at>> wrote:
> Note: this means we are finally dropping Ruby 1.8 support as
> TypedData requires Ruby 1.9 and later.

Unfortunately, TypedData is not an official API, yet,
so I'm hesitant to depend on it until it is official:

But there ought to be tiny gains made from dropping 1.8 support,
so I'll probably go ahead and do it...

Bráulio Bhavamitra | 26 Dec 13:17 2014

Rails/Unicorn comparizon between ruby 2.1.5 and ruby 2.2.0

Hello all,

A quick comparison the average GC time per request reported by Newrelic:

Ruby 2.1.5, Rails 3.2.21 and Unicorn: ~15ms
Ruby 2.1.5 (with gctools middleware), Rails 3.2.21 and Unicorn: ~4ms
Ruby 2.2.0, Rails 3.2.21 and Unicorn: ~8ms

We see that ruby 2.2.0 improved, but still an out-of-band is even better.


Eric Wong | 21 Dec 12:17 2014

[PATCH] remove SSL support

We implemented barely-advertised support for SSL for two reasons:

1) to detect corruption on LANs beyond what TCP offers
2) to support other servers based on unicorn (never happened)

Since this feature is largely not useful for unicorn itself,
there's no reason to penalize unicorn 5.x users with bloat.

In our defense, SSL support appeared in version 4.2.0 :)
 Note: generated with "git format-patch -D" to ease review

 lib/unicorn/configurator.rb     |   2 -
 lib/unicorn/http_server.rb      |   3 --
 lib/unicorn/ssl_client.rb       |  11 -----
 lib/unicorn/ssl_configurator.rb | 104 ----------------------------------------
 lib/unicorn/ssl_server.rb       |  42 ----------------
 test/unit/test_sni_hostnames.rb |  47 ------------------
 6 files changed, 209 deletions(-)
 delete mode 100644 lib/unicorn/ssl_client.rb
 delete mode 100644 lib/unicorn/ssl_configurator.rb
 delete mode 100644 lib/unicorn/ssl_server.rb
 delete mode 100644 test/unit/test_sni_hostnames.rb

diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb
index 5962418..d14e608 100644
--- a/lib/unicorn/configurator.rb
+++ b/lib/unicorn/configurator.rb
 <at>  <at>  -1,6 +1,5  <at>  <at> 
 # -*- encoding: binary -*-
(Continue reading)