lib/httpx/connection/http2.rb in httpx-0.18.0 vs lib/httpx/connection/http2.rb in httpx-0.18.1

- old
+ new

@@ -14,10 +14,16 @@ def initialize(id, code) super("stream #{id} closed with error: #{code}") end end + class GoawayError < Error + def initialize + super(0, :no_error) + end + end + attr_reader :streams, :pending def initialize(buffer, options) @options = Options.new(options) @settings = @options.http2_settings @@ -300,11 +306,11 @@ log(level: 2) { "#{stream.id}: closing stream" } @drains.delete(request) @streams.delete(request) - if error && error != :no_error + if error ex = Error.new(stream.id, error) ex.set_backtrace(caller) response = ErrorResponse.new(request, ex, request.options) emit(:response, request, response) else @@ -342,12 +348,19 @@ send_pending end def on_close(_last_frame, error, _payload) is_connection_closed = @connection.state == :closed - if error && error != :no_error + if error @buffer.clear if is_connection_closed - ex = Error.new(0, error) + if error == :no_error + ex = GoawayError.new + @pending.unshift(*@streams.keys) + @drains.clear + @streams.clear + else + ex = Error.new(0, error) + end ex.set_backtrace(caller) handle_error(ex) end return unless is_connection_closed && @streams.size.zero?