From d6880396bcf58cd6fbd2f993c743e7638579b82f Mon Sep 17 00:00:00 2001 From: Timofey Koolin Date: Fri, 14 Apr 2023 15:49:12 +0300 Subject: [PATCH] wait top stop background tasks before stop writer stream --- ydb/_topic_writer/topic_writer_asyncio.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ydb/_topic_writer/topic_writer_asyncio.py b/ydb/_topic_writer/topic_writer_asyncio.py index 567a2b52..30ab9fb3 100644 --- a/ydb/_topic_writer/topic_writer_asyncio.py +++ b/ydb/_topic_writer/topic_writer_asyncio.py @@ -366,8 +366,7 @@ async def _connection_loop(self): tasks = [send_loop, receive_loop] done, _ = await asyncio.wait([send_loop, receive_loop], return_when=asyncio.FIRST_COMPLETED) - await stream_writer.close() - done.pop().result() + done.pop().result() # need for raise exception - reason of stop task except issues.Error as err: err_info = check_retriable_error(err, retry_settings, attempt) if not err_info.is_retriable: @@ -380,12 +379,12 @@ async def _connection_loop(self): self._stop(err) return finally: - if stream_writer: - await stream_writer.close() for task in tasks: task.cancel() if tasks: await asyncio.wait(tasks) + if stream_writer: + await stream_writer.close() async def _encode_loop(self): try: