From 525ebb862e3c472123c64134e433b2684ec0db9b Mon Sep 17 00:00:00 2001 From: normal Date: Mon, 16 Oct 2017 04:33:53 +0000 Subject: webrick: fix up r60172 By making the socket non-blocking in r60172, TLS/SSL negotiation via the SSL_accept function must handle non-blocking sockets properly and retry on SSL_ERROR_WANT_READ/SSL_ERROR_WANT_WRITE. OpenSSL::SSL::SSLSocket#accept cannot do that properly with a non-blocking socket, so it must use non-blocking logic of OpenSSL::SSL::SSLSocket#accept_nonblock. Thanks to MSP-Greg (Greg L) for finding this. * lib/webrick/server.rb (start_thread): use SSL_accept properly with non-blocking socket. [Bug #14013] [Bug #14005] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/webrick/server.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/webrick') diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index 52a09f5186..2d678273e5 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -295,7 +295,15 @@ module WEBrick end if sock.respond_to?(:sync_close=) && @config[:SSLStartImmediately] WEBrick::Utils.timeout(@config[:RequestTimeout]) do - sock.accept # OpenSSL::SSL::SSLSocket#accept + + # we must call OpenSSL::SSL::SSLSocket#accept_nonblock until + # it stop returning wait_* symbols: + case ret = sock.accept_nonblock(exception: false) + when :wait_readable, :wait_writable + sock.to_io.__send__(ret) + else + break + end while true end end call_callback(:AcceptCallback, sock) -- cgit v1.2.3