Skip to content

Commit

Permalink
allow RST_STREAM to be received when a stream has been recently closed
Browse files Browse the repository at this point in the history
as per spec. fixed other tests wrongly using closed streams.
  • Loading branch information
HoneyryderChuck committed Jul 22, 2024
1 parent f55db20 commit 81b8359
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Layout/HeredocIndentation:
Metrics/BlockLength:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Lint/EmptyWhen:
Enabled: false

Expand Down
7 changes: 7 additions & 0 deletions lib/http/2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,13 @@ def receive(data)
stream = @streams_recently_closed[frame[:stream]]
connection_error(:protocol_error, msg: "sent window update on idle stream") unless stream
process_window_update(frame: frame, encode: true)
# Endpoints MUST ignore
# WINDOW_UPDATE or RST_STREAM frames received in this state (closed), though
# endpoints MAY choose to treat frames that arrive a significant
# time after sending END_STREAM as a connection error.
when :rst_stream
stream = @streams_recently_closed[frame[:stream]]
connection_error(:protocol_error, msg: "sent window update on idle stream") unless stream
else
# An endpoint that receives an unexpected stream identifier
# MUST respond with a connection error of type PROTOCOL_ERROR.
Expand Down
3 changes: 0 additions & 3 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@
it "should emit :altsvc" do
s = client.new_stream
s.send headers_frame
s.close

frame = nil
s.on(:altsvc) { |f| frame = f }
Expand All @@ -217,7 +216,6 @@
it "should not emit :alt_svc when the frame when contains a origin" do
s = client.new_stream
s.send headers_frame
s.close

frame = nil
s.on(:altsvc) { |f| frame = f }
Expand Down Expand Up @@ -270,7 +268,6 @@
it "should be ignored" do
s = client.new_stream
s.send headers_frame
s.close

expect do
client << set_stream_id(f.generate(orig_frame), s.id)
Expand Down
12 changes: 12 additions & 0 deletions spec/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,21 @@
stream.send data_frame
stream.close

# WINDOW_UPDATE or RST_STREAM frames can be received in this state
# for a short period
expect do
srv << f.generate(rst_stream_frame.merge(stream: stream.id))
end.to_not raise_error

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

# PRIORITY frames can be sent on closed streams to prioritize
# streams that are dependent on the closed stream.
expect do
srv << f.generate(priority_frame.merge(stream: stream.id))
end.to_not raise_error
end
end

Expand Down

0 comments on commit 81b8359

Please sign in to comment.