Skip to content

Commit 2a14008

Browse files
Treat NO_ERROR resets as orderly closure
Assisted-By: devx/618580b0-d55f-4c2e-95b6-87e648f60543
1 parent 10f4a47 commit 2a14008

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

‎lib/protocol/http2/stream.rb‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,21 @@ def open!
239239
return self
240240
end
241241

242-
# The stream has been closed. If closed due to a stream reset, the error will be set.
242+
# The stream has been closed. If closed due to a stream reset with a
243+
# non-zero error code, the error will be set.
243244
def closed(error = nil)
244245
end
245246

246247
# Transition the stream into the closed state.
247-
# @parameter error_code [Integer] the error code if the stream was closed due to a stream reset.
248+
# @parameter error_code [Integer | Nil] The error code if the stream was closed due to a stream reset.
248249
def close!(error_code = nil)
249250
@state = :closed
250251
@connection.delete(@id)
251252

252-
if error_code
253-
if error_code == REFUSED_STREAM
254-
error = ::Protocol::HTTP::RefusedError.new("Stream refused.")
255-
else
256-
error = StreamError.for(error_code)
257-
end
253+
if error_code == REFUSED_STREAM
254+
error = ::Protocol::HTTP::RefusedError.new("Stream refused.")
255+
elsif error_code && error_code != NO_ERROR
256+
error = StreamError.for(error_code)
258257
end
259258

260259
self.closed(error)

‎releases.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Treat `RST_STREAM(NO_ERROR)` as an orderly stream closure rather than
6+
constructing a `StreamError`.
7+
38
## v0.27.0
49

510
- On a graceful `GOAWAY` (error code `0`), keep the connection open until the streams the remote peer accepted have completed, instead of closing it immediately and failing those requests with `EOFError`.

‎test/protocol/http2/connection.rb‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,24 @@ def closed(error)
448448
expect(stream.error).to be_a(Protocol::HTTP::RefusedError)
449449
end
450450

451+
it "closes stream without an error on NO_ERROR" do
452+
stream = client.create_stream do |connection, id|
453+
stream_class.create(connection, id)
454+
end
455+
stream.send_headers(request_headers, Protocol::HTTP2::END_STREAM)
456+
457+
# Establish request stream on server:
458+
server.read_frame
459+
460+
# Server closes the stream without an error:
461+
server.streams[stream.id].send_reset_stream(Protocol::HTTP2::NO_ERROR)
462+
463+
client.read_frame
464+
465+
expect(stream.state).to be == :closed
466+
expect(stream.error).to be_nil
467+
end
468+
451469
it "closes unprocessed streams with RefusedError on graceful GOAWAY" do
452470
stream.send_headers(request_headers, Protocol::HTTP2::END_STREAM)
453471

0 commit comments

Comments
 (0)