PG::UnableToSend: server closed the connection unexpectedly...

Issue #247 closed
Rafael Sabatini
created an issue

Hi guys, We have the following configuration: RoR application + Sidekiq + PG gem + loadbalancer + Postgreql on Rackspace

Very often, when Sidekiq worker start processing DB request we got an error: PG::UnableToSend: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.

No error occurs out of sidekiq.

full log: https://gist.githubusercontent.com/igorkasyanchuk/cc96dba31b0b0f83b77faadf077433e8/raw/70af94105b0a7649b6ad0dde086ac539902d1d3f/gistfile1.txt

class RedZoneCrossedWorker < Worker
  def perform(event_id)
    Chewy.strategy(:atomic) do
      puts "#{self.class.name} Performing: #{event_id} #{jid}"
      event = RedZoneCrossedShipmentEvent.find_by(id: event_id)
      shipment = event.try(:shipment)
      if shipment
        # generate driver/oo payments
        shipment.generate_red_zone_payments
        # send mails and notifications if red zone crossed successfully
        notifier = event.successfully_completed? ? 'ShipmentNotifiers::ShipmentRedZoneSuccessNotifier' : 'ShipmentNotifiers::ShipmentRedZoneViolationsNotifier'
        ShipmentNotificationWorker.new.perform(event.shipment_id, notifier)
      end
    end
  end
end

also, here is very long performing:

2016-09-08T17:56:54.563Z 50179 TID-1gtxx8 RedZoneCrossedWorker JID-187ffc7f649b803c9c1b68b1 INFO: start
RedZoneCrossedWorker Performing: 163722 187ffc7f649b803c9c1b68b1
2016-09-08T19:52:22.284Z 50179 TID-1gtxx8 RedZoneCrossedWorker JID-187ffc7f649b803c9c1b68b1 INFO: done: 6927.721 sec

Any idea what is the problem, and how to fix it?

Comments (6)

  1. Log in to comment