Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQLAdapter::reconnect! fails when Postgres restarted (Rails 3.1) #3160

Closed
kranzky opened this issue Sep 29, 2011 · 5 comments
Closed

Comments

@kranzky
Copy link

kranzky commented Sep 29, 2011

Rails never recovers when we re-start Postgres; all subsequent requests fail as follows:

Started GET "/" for 127.0.0.1 at Thu Sep 29 10:32:28 +0800 2011

PGError (no connection to the server
):


Rendered .../actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered .../actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms)
Rendered .../actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (5.3ms)

Rails is detecting that the connection has gone away, and is calling into PostgreSQLAdapter::reconnect!, but this fails in the call to clear_cache!, which attempts to call @connection.query if @statements is non-empty.

We've monkeypatched the issue as follows:

module ActiveRecord
  module ConnectionAdapters
    class PostgreSQLAdapter < AbstractAdapter
      def reconnect!
        clear_cache! unless @connection.error_message =~ /no connection to the server/
        @connection.reset
        configure_connection
      end
    end
  end
end
@ileitch
Copy link

ileitch commented Oct 8, 2011

I've made a pull request to fix this issue: #3258

@mutru
Copy link

mutru commented Oct 20, 2011

+1, this took our production site down several times, and we almost had to rollback to Rails 3.0. The fix seems to work.

@ileitch
Copy link

ileitch commented Oct 20, 2011

@tenderlove appears to be one of the goto people for Postgres issues. Can we get this tagged for the 3.1.2 milestone?

@tenderlove
Copy link
Member

Sorry folks, I was going to merge this but it slipped my mind. I've merged to 3-1-stable and master. Thanks for the patch!

@colszowka
Copy link
Contributor

Unfortunately this did not resolve the problem for me. There's another open issue regarding this problem - I've added a couple of notes there. See #3392

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants