-
Notifications
You must be signed in to change notification settings - Fork 90
Description
Hello,
while porting my project to use a ConnectionPool
instead of many Connection
, I stumbled across an issue when:
- using the thin mode;
- setting the timeout to an integer (so not
None
); - and using a dynamic number of connections (i.e.
min
!=max
).
In this specific case, the ConnectionPool.acquire()
hangs and never returns a connection. I could identify the problem as due to to the following while loop. I'm not familiar enough with the library intrinsics to provide a PR though.
python-oracledb/src/oracledb/impl/thin/pool.pyx
Lines 329 to 333 in 7eb9be4
while self.get_open_count() > self.min and conn_impls_to_check: | |
conn_impl = conn_impls_to_check[0] | |
if current_time - conn_impl._time_in_pool > self._timeout: | |
conn_impls_to_check.pop(0) | |
self._drop_conn_impl(conn_impl) |
The project uses Python 3.8.13 with oracledb
1.3.1. The problem is however present since the feature implementation in c7c0d55.
Please find a minimal reproducible example below. The script blocks and never completes, staying in an endless loop in ConnectionPool.acquire()
.
import oracledb
from multiprocessing.pool import ThreadPool
pool = oracledb.create_pool("<REDACTED>", config_dir="/etc", min=1, max=5, timeout=10)
thread_pool = ThreadPool(processes = 5)
def wait(i):
with pool.acquire() as connection:
with connection.cursor() as cursor:
cursor.execute("""
BEGIN
DBMS_SESSION.sleep(1);
END; """)
print(f"Done {i}")
for i in range(10):
thread_pool.apply_async(wait, args=[i])
Thank you for any help. Let me know if you need more informations.