简体   繁体   English

ssl`sysread_nonblock':到达文件末尾(EOFError)

[英]ssl`sysread_nonblock': end of file reached (EOFError)

I have written a code which uses ruby threads. 我编写了一个使用ruby线程的代码。

require 'rubygems'
require 'net/http'
require 'uri'

def get_response()

  uri = URI.parse('https://..........')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  -----
  -----
end

t1 = []
15.times do |i|
t1[i] = Thread.new{
hit_mdm(i)
sleep(rand(0)/10.0)
}
end

t1.each {|t| t.join}

The code works fine, but when the programs reaches its end it throws following error: 代码工作正常,但当程序到达终点时,它会抛出以下错误:

ruby/2.0.0/openssl/buffering.rb:174:in `sysread_nonblock': end of file reached (EOFError) ruby / 2.0.0 / openssl / buffering.rb:174:在`sysread_nonblock'中:到达文件末尾(EOFError)

How to overcome this problem. 如何克服这个问题。

def getHttp(uri)
    begin       
        http = Net::HTTP.new(uri.host, uri.port)        
    rescue
        p 'failed Net::HTTP.new', uri
        retry       
    end
    http
end 

based on the downvoted answer, I attached some code to show an catch exception example 基于downvoted答案,我附上了一些代码来显示一个catch异常示例

You haven't specified what hit_mdm() is, but presumably it's something that calls get_response considering your Net::HTTP setup prior. 你没有指定hit_mdm()是什么,但可能是考虑到你之前的Net :: HTTP设置调用get_response。

There's many places on the web where you can find evidence that Net::HTTP is probably thread safe, though nothing conclusive. 网上有很多地方你可以找到证据证明Net :: HTTP 可能是线程安全的,但没有结论。

I've done lots of stress testing with Net::HTTP and threads and my experience is that the EOFErrors are common problems with multiple HTTP connections. 我已经使用Net :: HTTP和线程进行了大量的压力测试,我的经验是EOFErrors是多个HTTP连接的常见问题。 Whether it's happening because of the server or the client or the connection or the Net::HTTP library is going to be very difficult to debug, especially using threaded code which does TCP communication, which is also threaded, in a sense. 是否由于服务器或客户端或连接或Net :: HTTP库的发生将非常难以调试,特别是使用执行TCP通信的线程代码,在某种意义上也是线程化的。

You could use wireshark to figure out where the EOFError is coming from, or, you could save yourself a lot of headache and just rescue the EOFError on the sysread (your backtrace can tell you where to put the rescue so it's only effecting the Net::HTTP call, if that's where the EOFError is generated). 您可以使用wireshark来确定EOFError的来源,或者,您可以省去很多头痛并且只是在sysread上救出EOFError(您的回溯可以告诉您在何处进行救援,因此它只会影响网络: :HTTP调用,如果这是生成EOFError的地方)。

But without more info, we can't really tell you why the EOFError is happening for sure. 但没有更多信息,我们无法真正告诉你为什么EOFError肯定会发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM