[前][次][番号順一覧][スレッド一覧]

ruby-changes:48075

From: normal <ko1@a...>
Date: Mon, 16 Oct 2017 13:33:57 +0900 (JST)
Subject: [ruby-changes:48075] normal:r60189 (trunk): webrick: fix up r60172

normal	2017-10-16 13:33:53 +0900 (Mon, 16 Oct 2017)

  New Revision: 60189

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60189

  Log:
    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]

  Modified files:
    trunk/lib/webrick/server.rb
Index: lib/webrick/server.rb
===================================================================
--- lib/webrick/server.rb	(revision 60188)
+++ lib/webrick/server.rb	(revision 60189)
@@ -295,7 +295,15 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/server.rb#L295
           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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]