Farjad Adamjee | 1 Jul 18:08 2015

Unicorn returns blank page after no use


I am not sure if this is the correct place for this, I have googled 
around to see if anyone else has encountered such an issue, but I did 
not find anything.

I am having this issue where after a period of time of no use (on beta 
[production] environment), maybe 12 hours or so, the unicorn process 
sleeps. When I go and re-request the page, it returns blank.

I am using Apache proxy to Unicorn.

My unicorn.stderr.log states:
I, [2015-07-01T03:07:05.168511 #13258]  INFO -- : master done reopening logs
I, [2015-07-01T03:07:05.232546 #16222]  INFO -- : worker=2 done 
reopening logs
I, [2015-07-01T03:07:05.239934 #13308]  INFO -- : worker=0 done 
reopening logs
I, [2015-07-01T03:07:05.307616 #13311]  INFO -- : worker=1 done 
reopening logs

When I request the page again, it loads fine. It is only during the 
process of "reopening logs" when it returns a blank page.

My unicorn.rb file:

worker_processes 3

# Load app into the master before forking workers
# for super-fast worker spawn times
(Continue reading)

Eric Wong | 1 Jul 00:51 2015

[PATCH 0/3] reflect changes to Rack::Utils::HTTP_STATUS_CODES

A user privately reported (to unicorn <at> bogomips.org) that they wanted
status text reflected in their responses for an HTTP status code not
included with Rack::Utils::HTTP_STATUS_CODES.

They tried to modify Rack::Utils::HTTP_STATUS_CODES hash directly in
their app, but unicorn loads before their app and already memoized the
status codes internally in the CODES hash to reduce GC pressure, thus
their change was never reflected.

With the first change, users can change Rack::Utils::HTTP_STATUS_CODES
as many times as they want (perhaps even based on time-of-day, weather,
server load, whatever) and the changes will be reflected
instantaneously in responses.

Of course, this slows unicorn down slightly due to increased GC
pressure, but I doubt anybody would notice in Real World usage.
In case they do, patch 2/3 will recover the lost performance
if they're using Ruby 2.2+

I figure anybody who cares about micro-benchmark performance with
unicorn would be using the latest Rubies anyways...

That user is Bcc:-ed for these patches, and can follow any public
discussion at: http://bogomips.org/unicorn-public/
(including the Atom feed at http://bogomips.org/unicorn-public/atom.xml )

* [PATCH 1/3] reflect changes in Rack::Utils::HTTP_STATUS_CODES
  introduces a performance regression

* [PATCH 2/3] reduce constants and optimize for Ruby 2.2
(Continue reading)

Eric Wong | 27 Jun 04:57 2015

[PATCH] apply TCP socket options on inherited sockets

TCP socket options are now set when inheriting existing sockets from
a parent process.  I'm fairly certain all the TCP setsockopt knobs
we use are idempotent and harmless to change.

If anything, the only directive I'd be uncomfortable changing is
shortening the listen(2) (aka :backlog) size, but we've always
changed that anyways since it also applies to UNIX sockets.

Note: removing a configuration knob in a unicorn config file can not
reset the value to the OS-provided default setting.  Inherited
sockets must use a new setting to override existing ones.
(or the socket needs to be closed and re-created in the process
 launcher before unicorn inherits it).

Noticed-by: Christos Trochalakis <yatiohi <at> ideopolis.gr>
  <20150626114129.GA25883 <at> luke.ws.skroutz.gr>
 lib/unicorn/http_server.rb | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/unicorn/http_server.rb b/lib/unicorn/http_server.rb
index 3282ec7..297b9f9 100644
--- a/lib/unicorn/http_server.rb
+++ b/lib/unicorn/http_server.rb
 <at>  <at>  -768,10 +768,11  <at>  <at>  def inherit_listeners!
     # before they become Kgio::UNIXServer or Kgio::TCPServer
     inherited = ENV['UNICORN_FD'].to_s.split(',').map do |fd|
       io = Socket.for_fd(fd.to_i)
-      set_server_sockopt(io, listener_opts[sock_name(io)])
       io.autoclose = false
(Continue reading)

Bráulio Bhavamitra | 27 Jun 00:18 2015

Does the the environment is preserved on USR2?


I use the ruby environment variable RUBY_GC_MALLOC_LIMIT='90000000' to
start unicorn inside a init.d service and I get the impression that
when I run kill -USR2 `cat tmp/pids/unicorn.pid` in another shell this
variable is no longer used.

So the new master started by USR2 preserve the environment from the
old master or the environment variables need be set on the shell it is



"Lute pela sua ideologia. Seja um com sua ideologia. Viva pela sua
ideologia. Morra por sua ideologia" P.R. Sarkar

EITA - Educação, Informação e Tecnologias para Autogestão

"Paramapurusha é meu pai e Parama Prakriti é minha mãe. O universo é
meu lar e todos nós somos cidadãos deste cosmo. Este universo é a
imaginação da Mente Macrocósmica, e todas as entidades estão sendo
criadas, preservadas e destruídas nas fases de extroversão e
introversão do fluxo imaginativo cósmico. No âmbito pessoal, quando
uma pessoa imagina algo em sua mente, naquele momento, essa pessoa é a
única proprietária daquilo que ela imagina, e ninguém mais. Quando um
ser humano criado mentalmente caminha por um milharal também
(Continue reading)

Eric Wong | 26 Jun 21:46 2015

TAN: Ragel now maintained by Colm networks

As most of you know, unicorn has always used Ragel for HTTP
parsing (inherited from Mongrel).

For the most part, Ragel works great and does not need much
maintenance.  I made some changes to work with the Ragel 5-to-6
transition for Mongrel (pre-unicorn) and that was it.

Since I mainly use Ragel from the Debian package nowadays,
I missed this bit of news when it was posted 2014-10-24.


| As of October 2014, Ragel will be maintained by Colm Networks. 
| This is a new consulting company founded by Dr. Adrian D.
| Thurston.

(ed: Adrian Thurston is the original author of Ragel)

| Since we cannot operate in the open, the git repository for
| Ragel  will no longer be available. The project will be
| published as release (and pre-release) tarballs only. On the
| upside, Ragel will get much more attention.

*Sigh* I guess we'll need to diff release tarballs from now on...

I'm not very knowledgeable in C++, so any extra help auditing Ragel
changes would be greatly appreciated.

| The license will remain the same: GPLv2 with an exception for
| the generated code derived from Ragel source.
(Continue reading)

Eric Wong | 26 Jun 02:47 2015

[PATCH] doc: update some invalid URLs

Most of these were found by the `linkchecker' package
in Debian.
 Documentation/unicorn.1.txt       | 4 ++--
 Documentation/unicorn_rails.1.txt | 4 ++--
 KNOWN_ISSUES                      | 4 ++--
 Links                             | 3 ++-
 README                            | 2 +-
 SIGNALS                           | 2 +-
 Sandbox                           | 6 +++---
 lib/unicorn/http_server.rb        | 3 ++-
 8 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/Documentation/unicorn.1.txt b/Documentation/unicorn.1.txt
index b03962e..193860f 100644
--- a/Documentation/unicorn.1.txt
+++ b/Documentation/unicorn.1.txt
 <at>  <at>  -180,6 +180,6  <at>  <at>  startup, otherwise the socket will be closed.
 * [Rackup HowTo][3]

 [1]: http://unicorn.bogomips.org/
-[2]: http://rdoc.info/gems/r#/gems/rack/frames
-[3]: http://wiki.github.com/rack/rack/tutorial-rackup-howto
+[2]: http://www.rubydoc.info/github/rack/rack/
+[3]: https://github.com/rack/rack/wiki/tutorial-rackup-howto
 [4]: http://unicorn.bogomips.org/SIGNALS.html
diff --git a/Documentation/unicorn_rails.1.txt b/Documentation/unicorn_rails.1.txt
index c5db3a1..bff703e 100644
--- a/Documentation/unicorn_rails.1.txt
+++ b/Documentation/unicorn_rails.1.txt
(Continue reading)

Eric Wong | 26 Jun 01:26 2015

Re: [DRE-maint] unicorn: native systemd service

+Cc unicorn-public list 
Christos Trochalakis <christos <at> skroutz.gr> wrote:
> Hello all,
> I have recently migrated our main ruby application to systemd implementing zero
> downtime upgrades.
> systemd doesn't like replacing the binary on the fly. There is one exception to
> this, services with PIDFile. When PIDFile is set, systemd reads it when the
> main process exits and replaces the main process.  nginx also had this issue a
> few months ago [0].
> So, in order to support zero-downtime upgrades we have to use a pid file.

I don't think so.  You should be able to bind the listen socket in
systemd and rely on the socket activation features (setting the
UNICORN_FD environment variable to the created FD).

You still need to have the matching "listen" directive in the unicorn
config file so unicorn does not close it.

With socket activation, you should just be able to kill unicorn using
SIGQUIT (just master, or even all workers) and restart without ever
dropping a connection.  I do NOT suggest using SIGTERM for unicorn,
since that'll cause the master to kill all workers ASAP.

If the master dies before the workers (e.g. from SIGKILL),
systemd ought to just ignore the workers.

I don't actually know the systemd config at all, but anybody familiar
(Continue reading)

Eric Wong | 16 Jun 00:56 2015

[ANN] unicorn 5.0.0.pre1 - incompatible changes!

This release finally drops Ruby 1.8 support and requires Ruby 1.9.3
or later.  The horrible "Status:" header in our HTTP response is
finally gone, saving at least 16 precious bytes in every single HTTP

Under Ruby 2.1 and later, the monotonic clock is used for timeout
handling for better accuracy.

Several experimental, unused and undocumented features are removed.

There's also tiny, minor performance and memory improvements from
dropping 1.8 compatibility, but probably nothing noticeable on a
typical real-life (bloated) app.

The biggest performance improvement we made was to our website by
switching to olddoc.  Depending on connection speed, latency, and
renderer performance, it typically loads two to four times faster.

Finally, for the billionth time: unicorn must never be exposed
to slow clients, as it will never ever use new-fangled things
like non-blocking socket I/O, threads, epoll or kqueue.  unicorn
must be used with a fully-buffering reverse proxy such as nginx
for slow clients.

I'll tag 5.0.0 final in a week or so if all goes well

= gem install --pre unicorn
= git clone git://bogomips.org/unicorn.git
= http://unicorn.bogomips.org/

(Continue reading)

Eric Wong | 9 Jun 22:17 2015

[PATCH] ensure body is closed during hijack

Middlewares such as Rack::Lock (used by Rails) break badly unless
the response body is closed on hijack, so we will close it to follow
the lead of other popular Rack servers.

While it's unclear if there's anybody using rack.hijack with unicorn,
we'll try to emulate the behavior of other servers as much as

ref: https://github.com/ngauthier/tubesock/issues/10
 lib/unicorn/http_response.rb |  3 ---
 lib/unicorn/http_server.rb   | 20 +++++++++++++-------
 t/hijack.ru                  |  3 ++-
 t/t0200-rack-hijack.sh       |  7 +++++--
 test/unit/test_response.rb   | 11 -----------
 5 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb
index 801bf9a..016dac8 100644
--- a/lib/unicorn/http_response.rb
+++ b/lib/unicorn/http_response.rb
 <at>  <at>  -52,12 +52,9  <at>  <at>  module Unicorn::HttpResponse

     if hijack
-      body = nil # ensure we do not close body
       body.each { |chunk| socket.write(chunk) }
(Continue reading)

Eric Wong | 6 Jun 03:58 2015

[PATCH 0/2] eliminate generic ivars from HttpRequest class

With the mainline Ruby VM, generic instance variables are implemented as
a st (hash) table for each object costing at least 192 bytes.  This
isn't a huge problem for unicorn as it only ever allocates one
HttpRequest object, but still makes the HttpRequest class less suitable
for other servers.

While generic ivars will be less expensive when Ruby 2.3 is released in
December, we're still better off eliminating them entirely as they're
not going to be cheaper than T_OBJECT instance variables.

With this, I'll probably tag and release 5.0.0-rc1 soon.

Eric Wong (2):
      move the socket into Rack env for hijacking
      http: move response_start_sent into the C ext

 ext/unicorn_http/unicorn_http.rl | 26 +++++++++++++++++++++++---
 lib/unicorn/http_request.rb      |  9 ++++-----
 test/unit/test_http_parser_ng.rb | 11 +++++++++++
 3 files changed, 38 insertions(+), 8 deletions(-)

Note: Yes, [PATCH 1/2] introduces a unicorn-specific field into the
Rack env, but unicorn is not the only server with
`env["#{servername}.socket"]' in the Rack env.
And [PATCH 2/2] isn't useful without [PATCH 1/2]

Eric Wong | 5 Jun 10:49 2015

[PATCH] http_response: simplify regular expression

It's ugly and less-readable to have redundant \z statements, and
according to ObjectSpace.memsize_of, this saves 4 bytes on x86-64.
 lib/unicorn/http_response.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/unicorn/http_response.rb b/lib/unicorn/http_response.rb
index c9c2de8..801bf9a 100644
--- a/lib/unicorn/http_response.rb
+++ b/lib/unicorn/http_response.rb
 <at>  <at>  -33,7 +33,7  <at>  <at>  module Unicorn::HttpResponse
             "Connection: close\r\n"
       headers.each do |key, value|
         case key
-        when %r{\A(?:Date\z|Connection\z)}i
+        when %r{\A(?:Date|Connection)\z}i
         when "rack.hijack"
           # This should only be hit under Rack >= 1.5, as this was an illegal