From 00e78b06f3208cf6acdc6461a1abda35214e089d Mon Sep 17 00:00:00 2001 From: Alex Woods Date: Wed, 12 Mar 2025 10:05:52 -0700 Subject: [PATCH] Fix issue with BufferableByteStream after stream_close --- packages/smithy-http/src/smithy_http/aio/crt.py | 6 ++++-- packages/smithy-http/tests/unit/aio/test_crt.py | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/smithy-http/src/smithy_http/aio/crt.py b/packages/smithy-http/src/smithy_http/aio/crt.py index 58fa3ebae..ea72e822d 100644 --- a/packages/smithy-http/src/smithy_http/aio/crt.py +++ b/packages/smithy-http/src/smithy_http/aio/crt.py @@ -368,8 +368,10 @@ def read(self, size: int | None = -1) -> bytes: return b"" if len(self._chunks) == 0: - # When the CRT recieves this, it'll try again later. - raise BlockingIOError("read") + if self._done: + return b"" + else: + raise BlockingIOError("read") # We could compile all the chunks here instead of just returning # the one, BUT the CRT will keep calling read until empty bytes diff --git a/packages/smithy-http/tests/unit/aio/test_crt.py b/packages/smithy-http/tests/unit/aio/test_crt.py index d5c695417..f0264f1e5 100644 --- a/packages/smithy-http/tests/unit/aio/test_crt.py +++ b/packages/smithy-http/tests/unit/aio/test_crt.py @@ -87,6 +87,14 @@ def test_closed_stream_read() -> None: assert stream.read() == b"" +def test_done_stream_read() -> None: + stream = BufferableByteStream() + stream.write(b"foo") + stream.end_stream() + assert stream.read() == b"foo" + assert stream.read() == b"" + + def test_stream_read1() -> None: stream = BufferableByteStream() stream.write(b"foo")