Skip to content

Commit

Permalink
Merge 8e6e0d8 into ebcabd5
Browse files Browse the repository at this point in the history
  • Loading branch information
bengreenberg committed Feb 11, 2018
2 parents ebcabd5 + 8e6e0d8 commit 9ee2b32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/http/2/connection.rb
Expand Up @@ -656,15 +656,18 @@ def activate_stream(id: nil, **args)
# permitted to open.
stream.once(:active) { @active_stream_count += 1 }
stream.once(:close) do
@streams.delete id
@active_stream_count -= 1

# Store a reference to the closed stream, such that we can respond
# to any in-flight frames while close is registered on both sides.
# References to such streams will be purged whenever another stream
# is closed, with a minimum of 15s RTT time window.
@streams_recently_closed.delete_if { |_, v| (Time.now - v) > 15 }
@streams_recently_closed[id] = Time.now
to_delete = @streams_recently_closed.select { |_, v| (Time.now - v) > 15 }
to_delete.each do |stream_id|
@streams.delete stream_id
@streams_recently_closed.delete stream_id
end
end

stream.on(:promise, &method(:promise)) if self.is_a? Server
Expand Down
14 changes: 14 additions & 0 deletions spec/connection_spec.rb
Expand Up @@ -543,6 +543,20 @@
end.to raise_error(ProtocolError)
end

it 'should not raise an error on frame for a closed stream ID' do
srv = Server.new
srv << CONNECTION_PREFACE_MAGIC

stream = srv.new_stream
stream.send HEADERS.dup
stream.send DATA.dup
stream.close

expect do
srv << f.generate(RST_STREAM.dup.merge(stream: stream.id))
end.to_not raise_error
end

it 'should send GOAWAY frame on connection error' do
stream = @conn.new_stream

Expand Down

0 comments on commit 9ee2b32

Please sign in to comment.