Skip to content

Commit 94e9f57

Browse files
Close crt bridge stream on end_stream if empty
This is a followup to #432. I think the issue was that end_stream was getting called when the buffer was already empty, which would put it in an incomplete state. Unfortunately that fix also left it in an incomplete (but now working) state. This make sure it doesn't get into that incomplete state and adds a failing test for that case.
1 parent 0c9d105 commit 94e9f57

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/smithy-http/src/smithy_http/aio/crt.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,10 @@ def read(self, size: int | None = -1) -> bytes:
369369

370370
if len(self._chunks) == 0:
371371
if self._done:
372+
self.close()
372373
return b""
373374
else:
375+
# When the CRT recieves this, it'll try again
374376
raise BlockingIOError("read")
375377

376378
# We could compile all the chunks here instead of just returning
@@ -429,4 +431,7 @@ def close(self) -> None:
429431

430432
def end_stream(self) -> None:
431433
"""End the stream, letting any remaining chunks be read before it is closed."""
432-
self._done = True
434+
if len(self._chunks) == 0:
435+
self.close()
436+
else:
437+
self._done = True

packages/smithy-http/tests/unit/aio/test_crt.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def test_done_stream_read() -> None:
9595
assert stream.read() == b""
9696

9797

98+
def test_end_empty_stream() -> None:
99+
stream = BufferableByteStream()
100+
stream.end_stream()
101+
assert stream.read() == b""
102+
103+
98104
def test_stream_read1() -> None:
99105
stream = BufferableByteStream()
100106
stream.write(b"foo")

0 commit comments

Comments
 (0)