fix: connection pool exhaustion + cross_ref column name

- tenant_db.py: add rollback() before returning conn to pool to prevent
  'idle in transaction (aborted)' state that exhausts the pool
- tenant_db.py: increase pool maxconn from 10 to 20 for better concurrency
- inventory_vehicle_compat.py: fix column name cross_ref_number ->
  cross_reference_number to match actual schema
This commit is contained in:
2026-05-01 02:25:58 +00:00
parent 2b418701b6
commit 0e549e7746
2 changed files with 13 additions and 4 deletions

View File

@@ -21,7 +21,7 @@ def _get_master_pool():
global _master_pool
if _master_pool is None:
_master_pool = pool.ThreadedConnectionPool(
minconn=2, maxconn=10, dsn=MASTER_DB_URL
minconn=2, maxconn=20, dsn=MASTER_DB_URL
)
return _master_pool
@@ -32,7 +32,7 @@ def _get_tenant_pool(db_name):
if db_name not in _tenant_pools:
dsn = TENANT_DB_URL_TEMPLATE.format(db_name=db_name)
_tenant_pools[db_name] = pool.ThreadedConnectionPool(
minconn=2, maxconn=10, dsn=dsn
minconn=2, maxconn=20, dsn=dsn
)
return _tenant_pools[db_name]
@@ -52,6 +52,15 @@ class _PooledConnection:
def close(self):
try:
# Rollback any aborted transaction before returning to pool.
# Without this, failed transactions leave connections in
# 'idle in transaction (aborted)' state, eventually exhausting
# the pool.
if self._conn:
try:
self._conn.rollback()
except Exception:
pass
self._pool.putconn(self._conn)
except Exception:
# If pool is already closed, fall back to real close