Skip to content

Commit cacb4ea

Browse files
committed
Cancel queue get in case of cancel of parent.
1 parent 0dfe8e7 commit cacb4ea

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ydb/aio/table.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,14 @@ async def _prepare_session(self, timeout, retry_num) -> ydb.ISession:
563563
async def _get_session_from_queue(self, timeout: float):
564564
task_wait = asyncio.ensure_future(asyncio.wait_for(self._active_queue.get(), timeout=timeout))
565565
task_should_stop = asyncio.ensure_future(self._should_stop.wait())
566-
done, _ = await asyncio.wait((task_wait, task_should_stop), return_when=asyncio.FIRST_COMPLETED)
566+
try:
567+
done, _ = await asyncio.wait((task_wait, task_should_stop), return_when=asyncio.FIRST_COMPLETED)
568+
except asyncio.CancelledError as exc:
569+
cancelled = task_wait.cancel()
570+
if not cancelled:
571+
priority, session = task_wait.result()
572+
self._active_queue.put_nowait((priority, session))
573+
raise exc
567574
if task_should_stop in done:
568575
task_wait.cancel()
569576
return self._create()

0 commit comments

Comments
 (0)