From fd28741a97cc329616f83eb44a58d83f9b469804 Mon Sep 17 00:00:00 2001 From: HoneyryderChuck Date: Sun, 7 Feb 2021 15:44:27 +0000 Subject: [PATCH] fixing retry protocol bug for not-completely-flushed requests a bug was found where in certain cases, a server responds with an error before the request fully buffers the body. Under retries, the request is reset, however, the http/2 conn handler kept the last chunk around, which it would flush before writing the second request body, resulting in byte-accounting issues. Therefore, response clean up request state before yielding. --- lib/httpx/connection/http2.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/httpx/connection/http2.rb b/lib/httpx/connection/http2.rb index d81dfdc0..72e4c377 100644 --- a/lib/httpx/connection/http2.rb +++ b/lib/httpx/connection/http2.rb @@ -226,6 +226,10 @@ module HTTPX end def on_stream_close(stream, request, error) + log(level: 2) { "#{stream.id}: closing stream" } + @drains.delete(request) + @streams.delete(request) + if error && error != :no_error ex = Error.new(stream.id, error) ex.set_backtrace(caller) @@ -241,9 +245,6 @@ module HTTPX emit(:response, request, response) end end - log(level: 2) { "#{stream.id}: closing stream" } - - @streams.delete(request) send(@pending.shift) unless @pending.empty? return unless @streams.empty? && exhausted?