Ssl`sysread_nonblock ': end of file reached (EOFError)

I wrote code that uses ruby โ€‹โ€‹streams.

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 program reaches its end, it causes the following error:

ruby /2.0.0/openssl/buffering.rb: 174: in `sysread_nonblock ': end of file reached (EOFError)

How to solve this problem.

+6
source share
2 answers
 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 top-down answer, I have attached some code to show an example catch exception

0
source

You did not specify what hit_mdm () is, but presumably this is something that calls get_response based on the settings of Net :: HTTP earlier.

There are many places on the Internet where you can find evidence that Net :: HTTP is probably thread safe, but nothing final.

I have done a lot of stress testing with Net :: HTTP and threads, and my experience is that EOFErrors are common problems with multiple HTTP connections. Whether this is due to a server or client, or to a connection or Net :: HTTP library, it will be very difficult to debug, especially using streaming code that performs TCP communication, which also has threads in a sense.

You can use wirehark to find out where the EOFError comes from, or you could save a lot of headache and just save the EOFError on sysread (your backtrace can tell you where to put the rescue so that it only triggers a Net :: HTTP call, if that's where an EOFError is generated).

But without further information, we cannot tell you why an EOFError occurs exactly.

-1
source

Source: https://habr.com/ru/post/953674/


All Articles