Ruby Sinatra获取Net :: ReadTimeout - Net :: ReadTimeout

时间:2015-11-29 16:56:47

标签: ruby sinatra thin webrick

Bellow是我代码的一部分:

class VizApp < Sinatra::Base
  get '/rubygems' do
    @process_downloads_days = HTTParty.get('http://localhost:4567/api/v1/rubygems/version_downloads_days_process', timeout: 180)
    @version_downloads = HTTParty.get('http://localhost:4567/api/v1/rubygems/version_downloads')
    @version_downloads_days = HTTParty.get('http://localhost:4567/api/v1/rubygems/version_downloads_days')
    @version_downloads_stack = HTTParty.get('http://localhost:4567/api/v1/rubygems/version_downloads_stack')
    @version_downloads_nest_drilldown = HTTParty.get('http://localhost:4567/api/v1/rubygems/version_downloads_nest')
    erb :rubygems
end

我所做的就是调用我在同一个项目中编写的api。当我使用WEBrick作为我的网络服务器时,一切正常。但是,当我将Web服务器更改为Thin时,出现以下错误:

Net::ReadTimeout - Net::ReadTimeout: /Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/protocol.rb:158:in `rescue in rbuf_fill'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/protocol.rb:152:in `rbuf_fill'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/protocol.rb:134:in `readuntil'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/protocol.rb:144:in `readline'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http/response.rb:39:in `read_status_line'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http/response.rb:28:in `read_new'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1423:in `block in transport_request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1420:in `catch'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1420:in `transport_request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1393:in `request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1386:in `block in request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:853:in `start'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/2.3.0/net/http.rb:1384:in `request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/httparty-0.13.7/lib/httparty/request.rb:117:in `perform'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/httparty-0.13.7/lib/httparty.rb:545:in `perform_request'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/httparty-0.13.7/lib/httparty.rb:476:in `get'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/httparty-0.13.7/lib/httparty.rb:583:in `get'
/Users/chenlizhan/Desktop/Lee/Projects/repo-miner/visualization/app.rb:39:in `block in <class:VizApp>'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1610:in `block in compile!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `[]'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (3 levels) in route!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:993:in `route_eval'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:974:in `block (2 levels) in route!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1014:in `block in process_route'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `catch'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1012:in `process_route'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:972:in `block in route!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `each'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:971:in `route!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1084:in `block in dispatch!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1081:in `dispatch!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `block in call!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `block in invoke'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `catch'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1066:in `invoke'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:906:in `call!'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:894:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/show_exceptions.rb:21:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:181:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:2021:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `block in call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1795:in `synchronize'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:1486:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/tempfile_reaper.rb:15:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/lint.rb:49:in `_call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/lint.rb:37:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/sinatra-1.4.6/lib/sinatra/base.rb:218:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/chunked.rb:54:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/handler/thin.rb:19:in `run'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:286:in `start'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:147:in `start'
/Users/chenlizhan/.rvm/rubies/ruby-head/lib/ruby/gems/2.3.0/gems/rack-1.6.4/bin/rackup:4:in `<top (required)>'
/Users/chenlizhan/.rvm/gems/ruby-head/bin/rackup:23:in `load'
/Users/chenlizhan/.rvm/gems/ruby-head/bin/rackup:23:in `<main>'
/Users/chenlizhan/.rvm/gems/ruby-head/bin/ruby_executable_hooks:15:in `eval'
/Users/chenlizhan/.rvm/gems/ruby-head/bin/ruby_executable_hooks:15:in `<main>'

有人和我有类似的问题吗?请给我一个帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

我会在thin.yml中创建一个/config文件,然后设置timeout: 90或者使用您认为最合适的值。

然后,您可以在通过thin -C config/thin.yml

执行精简时指定配置文件