ruby net / http sysread_nonblock:到达文件末尾(EOFError)

时间:2015-05-12 07:04:12

标签: ruby https net-http

我有以下代码:

#!/usr/bin/env ruby

require 'net/http'

token = File.read("code.txt")
uri = URI("https://private.http.server.with.self.signed.certs")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
retjson = http.get("/api/conf/"+token)
puts retjson.body

这在我的macbookpro13 2010年中期8GB内存上运行良好。

我的新macbookpro15 2014年中期16GB上的相同代码引发了以下异常:

/Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/openssl/buffering.rb:174:in `sysread_nonblock': end of file reached (EOFError)
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/openssl/buffering.rb:174:in `read_nonblock'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:2563:in `read_status_line'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:2552:in `read_new'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1320:in `block in transport_request'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1317:in `catch'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1317:in `transport_request'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1294:in `request'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1287:in `block in request'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:746:in `start'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1285:in `request'
from /Users/lc/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/net/http.rb:1027:in `get'
from a.rb:10:in `<main>'

在两台机器上我都安装了相同的ruby 1.9.3-p551和相同的宝石。

如果我删除File.read行,那么异常会神奇地消失,如下所示:

#!/usr/bin/env ruby

require 'net/http'

# token = File.read("code.txt")
token = '56f3052f84e9b73c46df21c7d91620dc'
uri = URI("https://private.http.server.with.self.signed.certs")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
retjson = http.get("/api/conf/"+token)
puts retjson.body

谷歌搜索我发现net / http有一些随机行为取决于并发级别,但我错过了这一点。

任何建议或指针?

提前致谢 卢卡

0 个答案:

没有答案