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.
This commit is contained in:
HoneyryderChuck 2021-02-07 15:44:27 +00:00
parent 9ca4cbe68b
commit fd28741a97

View File

@ -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?