Skip to content

Commit

Permalink
Fix maximum_connection_streams -> @remote_settings. (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored Jun 10, 2024
1 parent 79e2283 commit ce23c76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def maximum_frame_size
@remote_settings.maximum_frame_size
end

# The maximum number of concurrent streams that this connection can initiate:
def maximum_concurrent_streams
@local_settings.maximum_concurrent_streams
@remote_settings.maximum_concurrent_streams
end

attr :framer
Expand Down Expand Up @@ -389,7 +390,8 @@ def receive_headers(frame)
raise ProtocolError, "Invalid stream id: #{stream_id} <= #{@remote_stream_id}!"
end

if @streams.size < self.maximum_concurrent_streams
# We need to validate that we have less streams than the specified maximum:
if @streams.size < @local_settings.maximum_concurrent_streams
stream = accept_stream(stream_id)
@remote_stream_id = stream_id

Expand Down
23 changes: 23 additions & 0 deletions test/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@
let(:framer) {Protocol::HTTP2::Framer.new(stream)}
let(:connection) {subject.new(framer, 1)}

with "#maximum_concurrent_streams" do
it "is the remote peer's maximum concurrent streams" do
connection.remote_settings.maximum_concurrent_streams = 10
connection.local_settings.current.maximum_concurrent_streams = 5

expect(connection.maximum_concurrent_streams).to be == 10
end
end

with '#receive_headers' do
it "fails with protocol error if exceeding the maximum concurrent connections" do
connection.local_settings.current.maximum_concurrent_streams = 1
# Create a stream to
connection.streams[1] = Protocol::HTTP2::Stream.new(connection, 1)

frame = Protocol::HTTP2::HeadersFrame.new(3)

expect do
connection.receive_headers(frame)
end.to raise_exception(Protocol::HTTP2::ProtocolError, message: be =~ /Exceeded maximum concurrent streams/)
end
end

it "reports the connection id 0 is not closed" do
expect(connection).not.to be(:closed_stream_id?, 0)
end
Expand Down

0 comments on commit ce23c76

Please sign in to comment.