是什么导致OpenSSL :: SSL :: SSLErrorWaitReadable“读取会阻塞”?

时间:2015-05-31 03:22:46

标签: ruby net-http

OpenSSL::SSL::SSLErrorWaitReadable "read would block"是什么意思?

我收到错误OpenSSL::SSL::SSLErrorWaitReadable,邮件为read would block。我认为这是因为超时,但我找不到有关该主题的任何文件。

任何人都可以帮我找出造成这种情况的原因吗?我还能做些什么来防止这个问题?

不时产生此错误的代码:

data = {hello: "world"}
path = "https://example.com/api"
uri = URI.parse(path)
http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = (uri.scheme == "https")
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
request.body = Oj.dump(data)
request["Content-Type"] = "application/json"
begin
    response = http.request(request) #this line produces the error.
rescue
    return nil
end

我在osx 2.1.5p273上使用ruby版本1.0.1i和openssl版本10.10.3

Versions are found using the command ruby -v -ropenssl -rfiddle -e 'puts Fiddle::Function.new(Fiddle.dlopen(nil)["SSLeay_version"], [Fiddle::TYPE_INT], Fiddle::TYPE_VOIDP).call(0)' 感谢@bayendor

1 个答案:

答案 0 :(得分:0)

无法在我的本地计算机上重现。有用。这是我的版本,你能用你的系统确认一下吗?或者,如果您的计算机是Mac并且您使用系统openssl和readline安装了ruby,则可能会因为它已经过时而导致。尝试安装新的openssl和readline并构建ruby,然后再次执行脚本。

% brew install openssl readline
% RUBY_CONFIGURE_OPTS="--enable-shared --with-readline-dir=$(brew --prefix readline) --with-openssl-dir=$(brew --prefix openssl)" rbenv install 2.0.0-p598
OS: MaxOSX 10.10.2  
ruby: 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin12.0]  
oj (2.12.9)
% ruby test.rb
OK

% cat test.rb

require 'uri'
require 'net/http'
require 'openssl'
require 'oj'

data = {hello: "world"}
path = "https://example.com/api"
uri = URI.parse(path)
http = Net::HTTP.new(uri.host, uri.port)

http.use_ssl = (uri.scheme == "https")
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
request = Net::HTTP::Post.new(uri.request_uri)
request.body = Oj.dump(data)
request["Content-Type"] = "application/json"
begin
    response = http.request(request) #this line produces the error.
    puts('OK')
rescue
    return nil
end