Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Receiving "ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() could not receive data from server: Connection timed out" in rake task

In my rake task, I'm connecting to postgresql via a pgbouncer setup. For some queries I receive this error:

ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() could not receive data from server: Connection timed out

In my pgbouncer log, I see this entry:

closing because: client unexpected eof (age=3110)

I have disabled prepared statements in my config/database.yml file and enabled transaction pool_mode in my pgbouncer config file. When I directly connect to postgres, I don't get this error.

Also in my rake task, I am creating multiple threads. I tried running ActiveRecord::Base.connection.reconnect! inside my threads as suggested here. That didn't help either.

I am using rails version 4.2.5 which has this fix. I'm still getting this error "could not receive data from server: Connection timed out".

like image 236
ignite Avatar asked Jul 10 '16 17:07

ignite


1 Answers

This was caused due to network issues in clients. Not able to reproduce since we migrated both server and client to Google Cloud Platform. Earlier our server was in DigitalOcean while our clients were in GCP.

like image 101
ignite Avatar answered Nov 11 '22 06:11

ignite