bugfix: prevent stream close callback from being called 2 times

an issue was observed when stream was closed from our side, that the
the request in-flight count on the connection. This was fixed by not
reacting to :stream_closed events if request has been previously deleted.
This commit is contained in:
HoneyryderChuck 2021-09-23 12:03:45 +01:00
parent 81a41d889c
commit 52948e0f83
3 changed files with 5 additions and 9 deletions

View File

@ -412,7 +412,8 @@ module HTTPX
AltSvc.emit(request, response) do |alt_origin, origin, alt_params|
emit(:altsvc, alt_origin, origin, alt_params)
end
handle_response
@response_received_at = Utils.now
@inflight -= 1
request.emit(:response, response)
end
parser.on(:altsvc) do |alt_origin, origin, alt_params|
@ -516,11 +517,6 @@ module HTTPX
remove_instance_variable(:@timeout) if defined?(@timeout)
end
def handle_response
@response_received_at = Utils.now
@inflight -= 1
end
def on_error(error)
if error.instance_of?(TimeoutError)

View File

@ -291,11 +291,13 @@ module HTTPX
end
def on_stream_refuse(stream, request, error)
stream.close
on_stream_close(stream, request, error)
stream.close
end
def on_stream_close(stream, request, error)
return if error == :stream_closed && !@streams.key?(request)
log(level: 2) { "#{stream.id}: closing stream" }
@drains.delete(request)
@streams.delete(request)

View File

@ -93,8 +93,6 @@ module HTTPX
def transition: (Symbol) -> void
def handle_response: () -> void
def on_error: (HTTPX::TimeoutError | Error | StandardError) -> void
def handle_error: (StandardError) -> void