Skip to content

Commit b3a8ebc

Browse files
authored
Fix issue with BufferableByteStream after stream_close (#432)
1 parent 28808f0 commit b3a8ebc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,10 @@ def read(self, size: int | None = -1) -> bytes:
368368
return b""
369369

370370
if len(self._chunks) == 0:
371-
# When the CRT recieves this, it'll try again later.
372-
raise BlockingIOError("read")
371+
if self._done:
372+
return b""
373+
else:
374+
raise BlockingIOError("read")
373375

374376
# We could compile all the chunks here instead of just returning
375377
# the one, BUT the CRT will keep calling read until empty bytes

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ def test_closed_stream_read() -> None:
8787
assert stream.read() == b""
8888

8989

90+
def test_done_stream_read() -> None:
91+
stream = BufferableByteStream()
92+
stream.write(b"foo")
93+
stream.end_stream()
94+
assert stream.read() == b"foo"
95+
assert stream.read() == b""
96+
97+
9098
def test_stream_read1() -> None:
9199
stream = BufferableByteStream()
92100
stream.write(b"foo")

0 commit comments

Comments
 (0)