我有两个通过HTTP进行通信的Rails应用程序。
应该接收请求的应用程序需要很长时间才能响应。我希望如此,所以使用我的首选请求方法(由httparty
gem提供)我增加超时并提交请求:
HTTParty.get("https://example.com", :timeout => 99999)
约。 2分钟,请求应用程序引发错误EOFError: end of file reached
,并显示以下堆栈跟踪:
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/protocol.rb:153:in `read_nonblock'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/protocol.rb:153:in `rbuf_fill'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/protocol.rb:134:in `readuntil'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/protocol.rb:144:in `readline'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/response.rb:39:in `read_status_line'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http/response.rb:28:in `read_new'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1414:in `block in transport_request'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1411:in `catch'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1411:in `transport_request'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1384:in `request'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1377:in `block in request'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:853:in `start'
from .rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/net/http.rb:1375:in `request'
from .rvm/gems/ruby-2.2.2/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform'
from .rvm/gems/ruby-2.2.2/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request'
from .rvm/gems/ruby-2.2.2/gems/httparty-0.13.7/lib/httparty.rb:476:in `get'
from .rvm/gems/ruby-2.2.2/gems/httparty-0.13.7/lib/httparty.rb:583:in `get'
from (irb):14
from .rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/console.rb:110:in `start'
from .rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/console.rb:9:in `start'
from .rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:68:in `console'
from .rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from .rvm/gems/ruby-2.2.2/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
但是在接收应用程序的日志中,我可以看到请求仍在处理中。因此,请求应用程序必须基于响应的其他内容来引发异常。
知道如何避免这种情况吗?