Skip to content

Commit a60e7d1

Browse files
committed
Ensure input and output is closed appropriately on error.
1 parent f9cef46 commit a60e7d1

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/async/http/protocol/http2/output.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ def stream(task)
7272
input = @stream.wait_for_input
7373

7474
@body.call(::Protocol::HTTP::Body::Stream.new(input, self))
75-
rescue Async::Stop
76-
# Ignore.
75+
rescue => error
76+
raise
77+
ensure
78+
input.close(error)
79+
self.close(error)
7780
end
7881

7982
# Reads chunks from the given body and writes them to the stream as fast as possible.
@@ -86,11 +89,13 @@ def passthrough(task)
8689
# chunk.clear unless chunk.frozen?
8790
# GC.start
8891
end
89-
90-
self.close
92+
rescue => error
93+
raise
9194
ensure
92-
@body&.close($!)
95+
@body&.close(error)
9396
@body = nil
97+
98+
self.close(error)
9499
end
95100

96101
# Send `maximum_size` bytes of data using the specified `stream`. If the buffer has no more chunks, `END_STREAM` will be sent on the final chunk.

0 commit comments

Comments
 (0)