11

What does the OpenSSL::SSL::SSLErrorWaitReadable "read would block" mean?

I am getting the error OpenSSL::SSL::SSLErrorWaitReadable with the message read would block. I think this is because of timeouts, but I can't find any documentation on the subject.

Can anyone help me figure out what is causing this? Also what I can do to prevent the issue?

The code that is producing this error every now and then:

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

I am using ruby version 2.1.5p273 and openssl version 1.0.1i on osx 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)' Thanks to @bayendor

Community
  • 1
  • 1
Automatico
  • 12,420
  • 9
  • 82
  • 110

1 Answers1

0

Couldn't reproduce in my local machine. It works. Here is my version, so could you confirm with your system? Or if your machine is Mac and you installed ruby with system openssl and readline, it may cause because it's old. Try to install new openssl and readline and build ruby, then execute the script again.

% 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
mttr
  • 49
  • 7
  • I use ruby `2.1.5p273` and it appears to be using openssl version `1.0.1i` on mac osx 10.10.3. – Automatico May 31 '15 at 16:07
  • What about using **openssl version > 1.0.2** for ruby build? You get still the error? – mttr May 31 '15 at 16:31
  • Well, it might cause the error to go away, but I am really wondering what the error means. – Automatico May 31 '15 at 16:56
  • This is the source code. I don't know well the lib, but you will see how it is implemented. Hope it help your understanding. https://www.omniref.com/ruby/2.1.2/symbols/OpenSSL::SSL::SSLErrorWaitReadable – mttr May 31 '15 at 17:22
  • Thanks :) I have looked through it actually, but I wasn't able to figure much out. Looking at it again I found this: http://stackoverflow.com/questions/3952104/how-to-handle-openssl-ssl-error-want-read-want-write-on-non-blocking-sockets which might suggest something is using the same socket to write and something else is reading at the same time.. Will investigate – Automatico May 31 '15 at 17:30
  • Have you found the root issue? – Dmitry Polushkin Aug 28 '15 at 09:12