Skip to content

Commit 1c0807f

Browse files
committed
refactor sync pool timeout
1 parent 2f6f9b3 commit 1c0807f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ydb/query/pool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Optional,
55
List,
66
)
7+
import time
78
import threading
89
import queue
910

@@ -56,6 +57,7 @@ def acquire(self, timeout: float) -> QuerySessionSync:
5657
except queue.Empty:
5758
pass
5859

60+
start = time.monotonic()
5961
if session is None and self._current_size == self._size:
6062
try:
6163
_, session = self._queue.get(block=True, timeout=timeout)
@@ -72,6 +74,11 @@ def acquire(self, timeout: float) -> QuerySessionSync:
7274

7375
logger.debug(f"Session pool is not large enough: {self._current_size} < {self._size}, will create new one.")
7476
session = self._create_new_session()
77+
78+
finish = time.monotonic()
79+
if finish - start > timeout:
80+
session.delete()
81+
raise issues.SessionPoolEmpty("Timeout on acquire session")
7582
self._current_size += 1
7683
return session
7784

0 commit comments

Comments
 (0)