From bf8062141269b97096dffe1c1b4c087840cee821 Mon Sep 17 00:00:00 2001 From: Tiago Cardoso Date: Thu, 1 Oct 2026 17:09:13 +0100 Subject: [PATCH] do not wait for requests if the ssl socket already buffered bytes A condition may happen where a socket may have have already drained the bytes to the TLS layer; this would cause this particular "keep alive while waiting for next request" hanging, despite the client having sent the request already, because the wait_readable call is performed on the TCPSocket, not on the SSLSocket (which anyway, I don't think the implementations check pending bytes either). --- lib/webrick/httpserver.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb index 0d261bf0..bbb98c09 100644 --- a/lib/webrick/httpserver.rb +++ b/lib/webrick/httpserver.rb @@ -74,6 +74,11 @@ def run(sock) begin timeout = @config[:RequestTimeout] while timeout > 0 + # at this point, the client may have already sent data which was + # read by the socket, but openssl may have already buffered it. + # This happens way more in JRuby due to JVM thread scheduling. + break if sock.respond_to?(:pending) && sock.pending > 0 + break if sock.to_io.wait_readable(0.5) break if @status != :Running timeout -= 0.5