Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove closed streams immediately #120

Merged
merged 1 commit into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/http/2/connection.rb
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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