@@ -252,18 +252,26 @@ def run(sock)
252252 # the client socket.
253253
254254 def accept_client ( svr )
255- sock = nil
256- begin
257- sock = svr . accept
258- sock . sync = true
259- Utils ::set_non_blocking ( sock )
260- rescue Errno ::ECONNRESET , Errno ::ECONNABORTED ,
261- Errno ::EPROTO , Errno ::EINVAL
262- rescue StandardError => ex
263- msg = "#{ ex . class } : #{ ex . message } \n \t #{ ex . backtrace [ 0 ] } "
264- @logger . error msg
255+ case sock = svr . to_io . accept_nonblock ( exception : false )
256+ when :wait_readable
257+ nil
258+ else
259+ if svr . respond_to? ( :start_immediately )
260+ sock = OpenSSL ::SSL ::SSLSocket . new ( sock , ssl_context )
261+ sock . sync_close = true
262+ # we cannot do OpenSSL::SSL::SSLSocket#accept here because
263+ # a slow client can prevent us from accepting connections
264+ # from other clients
265+ end
266+ sock
265267 end
266- return sock
268+ rescue Errno ::ECONNRESET , Errno ::ECONNABORTED ,
269+ Errno ::EPROTO , Errno ::EINVAL
270+ nil
271+ rescue StandardError => ex
272+ msg = "#{ ex . class } : #{ ex . message } \n \t #{ ex . backtrace [ 0 ] } "
273+ @logger . error msg
274+ nil
267275 end
268276
269277 ##
@@ -286,6 +294,16 @@ def start_thread(sock, &block)
286294 @logger . debug "accept: <address unknown>"
287295 raise
288296 end
297+ if sock . respond_to? ( :sync_close= ) && @config [ :SSLStartImmediately ]
298+ WEBrick ::Utils . timeout ( @config [ :RequestTimeout ] ) do
299+ begin
300+ sock . accept # OpenSSL::SSL::SSLSocket#accept
301+ rescue Errno ::ECONNRESET , Errno ::ECONNABORTED ,
302+ Errno ::EPROTO , Errno ::EINVAL
303+ Thread . exit
304+ end
305+ end
306+ end
289307 call_callback ( :AcceptCallback , sock )
290308 block ? block . call ( sock ) : run ( sock )
291309 rescue Errno ::ENOTCONN
0 commit comments