1

我有一个奇怪的问题,我想知道是否有其他人遇到过。

我们在 jruby 1.6.2 下运行 resque

我们有一个长期运行的任务,它从各种 URL 下载一堆文件,使用 Fog 将这些文件上传到 Rackspace Cloudfiles,然后将有关这些文件的一些信息存储在 MySQL 中。在这种情况持续了一段时间之后,我们的应用程序的网络堆栈似乎崩溃了。在一个例子中,失败的第一个迹象是从这里超时:

org/jruby/ext/openssl/SSLSocket.java:512:in `sysread'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/jruby-openssl-0.7.4/lib/openssl/buffering.rb:35:in `fill_rbuff'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/jruby-openssl-0.7.4/lib/openssl/buffering.rb:158:in `eof?'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/jruby-openssl-0.7.4/lib/openssl/buffering.rb:133:in `readline'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/excon-0.6.5/lib/excon/response.rb:22:in `parse'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/excon-0.6.5/lib/excon/connection.rb:174:in `request'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/fog-0.11.0/lib/fog/core/connection.rb:20:in `request'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/fog-0.11.0/lib/fog/storage/rackspace.rb:107:in `request'

我们通常会在作业运行大约 10-15 分钟后开始看到这些问题。在那之后,我们开始在每次尝试写入数据库时​​看到这一点......

ActiveRecord::JDBCError: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.: SELECT `bills`.* FROM `bills` WHERE (`bills`.state_session_id = 59)
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.: SELECT `bills`.* FROM `bills` WHERE (`bills`.state_session_id = 59)
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract_adapter.rb:207:in `log'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract_adapter.rb:200:in `log'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.1.1/lib/arjdbc/jdbc/adapter.rb:183:in `execute'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-jdbc-adapter-1.1.1/lib/arjdbc/jdbc/adapter.rb:275:in `select'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/base.rb:473:in `find_by_sql'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/relation.rb:64:in `to_a'
/var/www/lisausa/shared/bundle/jruby/1.9/gems/activerecord-3.0.10/lib/active_record/relation/finder_methods.rb:143:in `all'

我尝试使用 ruby​​-cloudfiles gem 代替 Fog,但我们似乎也开始遇到完全相同的错误,最终也使用该组合。如果我禁用文件下载/云文件上传这部分,这些错误永远不会出现,并且我已经能够让这个特定的工作运行数天。

关于这里可能发生什么的任何理论?

4

1 回答 1

0

对于它的价值,几个月后,我可以告诉你

“ActiveRecord::JDBCError: 无法从服务器读取响应。预期读取 4 个字节,在连接意外丢失之前读取 0 个字节......”

通常对我们来说,数据库连接已断开(由于网络问题,或数据库关闭等)并且底层套接字已关闭。至少对我们来说,JRuby/ActiveRecord/ConnectionPool 的默认行为是在每个命令上不断出现此错误,而不是重新连接。

于 2012-04-26T15:32:53.540 回答