Skip to content

"PG::Error: connection is closed" when enqueuing a job in a connection shared with ActiveRecord #141

Closed

Description

@raul

We're using QC 2.1.3 in a Rails 3.2.13 app, with the version 0.14.1 of the pg gem. Sometimes we get a PG::Error: connection is closed error when enqueuing jobs. Unfortunately I haven't been able to reproduce the problem in a controlled environment.

Enqueuing code:

module Approvable

  extend ActiveSupport::Concern

  included do
    # ...
    after_save :queue_approval_notification
  end

  # ...

  def queue_approval_notification
    send_email = approvable? && (just_approved? || just_unapproved?)
    QC.enqueue("#{self.class}.email_approval_notification", self.id, approved?, current_user.email) if send_email
  end

Error stacktrace:

2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/conn.rb:81:in `finish'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/conn.rb:81:in `disconnect'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/conn.rb:19:in `rescue in block in execute'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/conn.rb:11:in `block in execute'
2013-04-06T00:11:24+00:00 app[web.1]: <internal:prelude>:10:in `synchronize'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/conn.rb:9:in `execute'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/queries.rb:8:in `block in insert'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic.rb:78:in `log_yield'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/queries.rb:6:in `insert'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic/queue.rb:11:in `enqueue'
2013-04-06T00:11:24+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/queue_classic-2.1.3/lib/queue_classic.rb:61:in `method_missing'
2013-04-06T00:11:24+00:00 app[web.1]: /app/app/models/approvable.rb:131:in `queue_approval_notification'

Activity

  1. senny commented on Apr 8, 2013

    @senny
    Contributor

    Do you use QC_DATABASE_URL to connect to your database or do you reuse a connection for example from Active Record?

  2. raul commented on Apr 8, 2013

    @raul
    Author

    I share Active Record´s:

    require 'queue_classic'
    QC::Conn.connection = ActiveRecord::Base.connection.raw_connection
  3. senny commented on Apr 9, 2013

    @senny
    Contributor

    reusing the Active Record connection is not working flawlessly at the moment. You can find the discussion here #96 and here #134.

  4. raul commented on Apr 10, 2013

    @raul
    Author

    Good call, thanks! We're using it with its own connection now, I'll update the issue if we notice it gets more stable.

  5. raul commented on Apr 12, 2013

    @raul
    Author

    This is looking good - no issues since we stopped sharing the ActiveRecord connection.

  6. senny commented on Apr 12, 2013

    @senny
    Contributor

    great! Thanks for reporting ❤️ let me close this one for now as it is not related to the QC core. I am working on a better integration with Rails so I hope to resolve this problem in the future: #134

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions