unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: Joe Van Dyk <joe@tanga.com>
Cc: mongrel-unicorn@rubyforge.org
Subject: Re: Fwd: Zero-downtime deploys, signals, ruby-pg
Date: Wed, 20 Nov 2013 09:47:17 +0000	[thread overview]
Message-ID: <20131120094717.GA17836@dcvr.yhbt.net> (raw)
In-Reply-To: <CACfv+p+4FK5BSL4D0uMi-Zgtf7VtcpTVu7sG4WXv2YXWyRbeWA@mail.gmail.com>

Joe Van Dyk <joe@tanga.com> wrote:
> Just sent this via gmail. Any ideas why I got this error?

It contained an HTML portion which Mailman couldn't strip or handle.
Forwarding to the list for now[1]

> ---------- Forwarded message ----------
> From: Joe Van Dyk <joe@tanga.com>
> To: unicorn list <mongrel-unicorn@rubyforge.org>
> Cc:
> Date: Tue, 19 Nov 2013 15:29:27 -0800
> Subject: Zero-downtime deploys, signals, ruby-pg
> Hi folks,
> 
> I think the upgrade to ruby-pg 0.16 broke the zero-downtime deployments on
> unicorn.
> 
> See mailing list post here:
> https://groups.google.com/d/msg/ruby-pg/5_ylGmog1S4/uvQ3EDl7MUUJ
> 
> I think the problem is that unicorn sends a signal to the worker thread
> when it's about to be shutdown. ruby-pg receives that signal and
> immediately cancels any actively-running queries. Leading to exceptions
> like:
> 
> PG::QueryCanceled: ERROR: canceling statement due to user request : UPDATE
> "orders" SET...
> from deep inside Sequel or ActiveRecord.
> 
> Michael Granger said it's a unicorn problem (apparently).

Unfortunately, there's no easy solution in unicorn.

ruby-pg is correct in interrupting the running query since it doesn't
know if the interrupt signal is for graceful unicorn shutdown or if the
user is thinking: "must stop query now or all data is destroyed!"

So I suspect ruby-pg favors the panicking user who accidentally issued
an UPDATE or DELETE without a proper WHERE clause :)

As far as workarounds on the unicorn/rack-side go:

1) retry on PG::QueryCanceled queries, this is analogous to the
   EINTR retries Ruby does for most interrupted syscalls.
   However, this takes time and you need to be careful in case
   you forgot transactions and what not.

2) Avoid SIGQUIT on the unicorn master completely, just send SIGKILL
   to the master.  The workers will slowly realize the master is dead
   and die gracefully.  This could increase RAM usage.
_______________________________________________
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:[~2013-11-20  9:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.0.1384904190.12484.mongrel-unicorn@rubyforge.org>
     [not found] ` <CACfv+p+4FK5BSL4D0uMi-Zgtf7VtcpTVu7sG4WXv2YXWyRbeWA@mail.gmail.com>
2013-11-20  9:47   ` Eric Wong [this message]
2013-11-20 10:06     ` Fwd: Zero-downtime deploys, signals, ruby-pg Eric Wong

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=20131120094717.GA17836@dcvr.yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=joe@tanga.com \
    --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).