Getting PG::ConnectionBad: PQconsumeInput() server closed the connection unexpectedly in a Rails Sidekiq job


I migrated a Rails app from Heroku, and in Sidekiq after a long job that takes more than 1 hour to complete I’m getting this error when the job tries to access the Postgres DB:

I’m not seeing anything suspicious in the logs and metrics.

Anyone else had a similar problem?

I had a similar problem, and it went away when I specified the Sidekiq worker in the [process] block. It might be coincidental but I thought it was worth sharing.

@mcart hey, have you found the solution?

Getting this too. Restarted the machine and it went away. A few things:

  • Our machines are in SYD (app and DB)
  • This happens both on the sidekiq process and on regular rails server/console processes
  • Last time this happened on sidekiq, the machine was close to OOM. Might be just a coincidence though, it did not crash