Skip to content

Commit c1117ca

Browse files
committed
Fix handling of stream close_write.
1 parent f4f2e6c commit c1117ca

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

fixtures/async/http/a_protocol.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ module HTTP
137137
if trailer = request.headers['trailer']
138138
expect(request.headers).not.to have_keys('etag')
139139

140-
request_received.value = true; pp request.body
141-
pp finish: request.finish
140+
request_received.value = true
141+
request.finish
142142

143143
expect(request.headers).to have_keys('etag')
144144

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,16 @@ def write(chunk)
5151
end
5252

5353
def close_write(error = nil)
54-
close(error)
54+
if stream = @stream
55+
@stream = nil
56+
stream.finish_output(error)
57+
end
5558
end
5659

5760
# This method should only be called from within the context of the output task.
5861
def close(error = nil)
62+
close_write(error)
5963
stop(error)
60-
61-
if stream = @stream
62-
@stream = nil
63-
stream.finish_output(error)
64-
end
6564
end
6665

6766
# This method should only be called from within the context of the HTTP/2 stream.
@@ -99,12 +98,14 @@ def passthrough(task)
9998
rescue => error
10099
raise
101100
ensure
102-
if @body
103-
@body.close(error)
101+
# Ensure the body we are reading from is fully closed:
102+
if body = @body
104103
@body = nil
104+
body.close(error)
105105
end
106106

107-
self.close(error)
107+
# Ensure the output of this body is closed:
108+
self.close_write(error)
108109
end
109110

110111
# 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)