【问题标题】:What causes OpenSSL::SSL::SSLErrorWaitReadable "read would block"?是什么导致 OpenSSL::SSL::SSLErrorWaitReadable “读取会阻塞”?
【发布时间】:2023-03-15 02:28:01
【问题描述】:

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 10.10.3 上使用 ruby​​ 版本 2.1.5p273 和 openssl 版本 1.0.1i

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

【问题讨论】:

    标签: ruby net-http


    【解决方案1】:

    无法在我的本地机器上重现。有用。这是我的版本,你能用你的系统确认一下吗?或者,如果您的机器是 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
    

    【讨论】:

    • 我使用 ruby​​ 2.1.5p273,它似乎在 mac osx 10.10.3 上使用 openssl 版本 1.0.1i
    • 使用 openssl version > 1.0.2 构建 ruby​​ 怎么样?你仍然得到错误?
    • 好吧,它可能会导致错误消失,但我真的想知道错误是什么意思。
    • 这是源代码。我不太了解这个库,但你会看到它是如何实现的。希望对您的理解有所帮助。 omniref.com/ruby/2.1.2/symbols/…
    • 谢谢 :) 我实际上已经看过它,但我无法弄清楚。再看一遍我发现:stackoverflow.com/questions/3952104/… 这可能表明某些东西正在使用同一个套接字进行写入,而其他东西正在同时读取.. 将调查
    猜你喜欢
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 1970-01-01
    • 2010-11-28
    相关资源
    最近更新 更多