Rainbows! Rack HTTP server user/dev discussion
 help / color / mirror / code / Atom feed
From: "Lin Jen-Shin (godfat)" <godfat-hOE/xeEBYYIdnm+yROfE0A@public.gmane.org>
To: "Rainbows! list" <rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org>
Subject: Re: leakage of sockets or activerecord connections
Date: Fri, 23 Aug 2013 06:46:18 +0800	[thread overview]
Message-ID: <CAA2_N1soVYiNkRgZqa+mLO26KUzvTAXuk0gA9Qo7MPrZ0+bNXw@mail.gmail.com> (raw)
In-Reply-To: <52168D10.8080407-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org>

On Fri, Aug 23, 2013 at 6:13 AM, Corin Langosch <info-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org> wrote:
> Hi,
> I wonder if I have to setup and hooks (like in unicorn before_fork etc.)? In
> fact I'd expect this happens automatically as the thread exits after the
> request is completed?
> Thanks,
> Corin

No, I think you should probably insert this middleware on top of your app:


This is actually what Rails did for itself. Here's what it is doing:

    class ConnectionManagement
      def initialize(app)
        @app = app

      def call(env)
        testing = env.key?('rack.test')

        response = @app.call(env)
        response[2] = ::Rack::BodyProxy.new(response[2]) do
          ActiveRecord::Base.clear_active_connections! unless testing

        ActiveRecord::Base.clear_active_connections! unless testing

p.s. By pasting you this, now I understood why Rails works a bit
differently with threads in tests. Oh well. Maybe I should patch it.
Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org
Do not quote signatures (like this one) or top post when replying

  parent reply	other threads:[~2013-08-22 23:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-22 22:13 leakage of sockets or activerecord connections Corin Langosch
     [not found] ` <52168D10.8080407-FIgL9nsKG9THeUWFKdsAYQC/G2K4zDHf@public.gmane.org>
2013-08-22 22:45   ` Eric Wong
2013-08-22 22:46   ` Lin Jen-Shin (godfat) [this message]
     [not found]     ` <CAA2_N1soVYiNkRgZqa+mLO26KUzvTAXuk0gA9Qo7MPrZ0+bNXw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-08-27 12:31       ` Corin Langosch

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:

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

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

  git send-email \
    --in-reply-to=CAA2_N1soVYiNkRgZqa+mLO26KUzvTAXuk0gA9Qo7MPrZ0+bNXw@mail.gmail.com \
    --to=godfat-hoe/xeebyyidnm+yrofe0a@public.gmane.org \
    --cc=rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org \


* 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


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).