Skip to content

Commit e1ecd23

Browse files
authored
Close request when initial response fails and propagate error (#454)
1 parent 06f872b commit e1ecd23

File tree

2 files changed

+8
-3
lines changed
  • codegen/core/src/main/java/software/amazon/smithy/python/codegen
  • packages/smithy-http/src/smithy_http/aio

2 files changed

+8
-3
lines changed

codegen/core/src/main/java/software/amazon/smithy/python/codegen/ClientGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,9 @@ async def _wrap_duplex_output(
320320
request_future, response_future,
321321
)
322322
except Exception as e:
323-
if request_future is not None and not request_future.done:
323+
if request_future is not None and not request_future.done():
324324
request_future.set_exception($4T(e))
325-
if response_future is not None and not response_future.done:
325+
if response_future is not None and not response_future.done():
326326
response_future.set_exception($4T(e))
327327
328328
# Make sure every exception that we throw is an instance of $4T so

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,12 @@ async def send(
251251
crt_stream.completion_future.add_done_callback(
252252
partial(self._close_input_body, body=crt_body)
253253
)
254-
return await response_factory.await_response()
254+
255+
response = await response_factory.await_response()
256+
if response.status != 200 and response.status >= 300:
257+
await close(crt_body)
258+
259+
return response
255260

256261
def _close_input_body(
257262
self, future: ConcurrentFuture[int], *, body: "BufferableByteStream | BytesIO"

0 commit comments

Comments
 (0)