接收"ActiveRecord :: StatementInvalid:PG :: ConnectionBad:PQconsumeInput()无法从服务器接收数据:连接超时"在rake任务中

ign*_*ite 5 postgresql activerecord multithreading ruby-on-rails pgbouncer

在我的rake任务中,我通过pgbouncer设置连接到postgresql.对于某些查询,我收到此错误:

ActiveRecord::StatementInvalid: PG::ConnectionBad: PQconsumeInput() could not receive data from server: Connection timed out
Run Code Online (Sandbox Code Playgroud)

在我的pgbouncer日志中,我看到了这个条目:

closing because: client unexpected eof (age=3110)
Run Code Online (Sandbox Code Playgroud)

我在我的config/database.yml文件中禁用transaction pool_mode了预准备语句,并在我的pgbouncer配置文件中启用.当我直接连接到postgres时,我没有收到此错误.

同样在我的rake任务中,我正在创建多个线程.我ActiveRecord::Base.connection.reconnect!按照这里的建议尝试在我的线程内运行.这也没有帮助.

我正在使用rails版本4.2.5,它有此修复程序.我仍然收到此错误"无法从服务器接收数据:连接超时".

ign*_*ite 1

这是由于客户端的网络问题造成的。由于我们将服务器和客户端都迁移到 Google Cloud Platform,因此无法重现。早些时候,我们的服务器位于 DigitalOcean,而我们的客户端位于 GCP。