Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: increase QueuePool size to prevent connection timeouts (#3353)

LearningCircuit91c1d63a1962
diff --git a/src/local_deep_research/database/auth_db.py b/src/local_deep_research/database/auth_db.py
index 59cab447d7..ea04c4aa72 100644
--- a/src/local_deep_research/database/auth_db.py
+++ b/src/local_deep_research/database/auth_db.py
@@ -72,13 +72,14 @@ def _get_auth_engine() -> Engine:
if not auth_db_path.exists():
init_auth_database()
- # Minimal pool — auth DB is unencrypted SQLite, low concurrency.
+ # Moderate pool — auth DB is unencrypted SQLite used by every
+ # authenticated request via before_request middleware.
# See ADR-0004 for pool sizing rationale.
_auth_engine = create_engine(
f"sqlite:///{auth_db_path}",
poolclass=QueuePool,
- pool_size=1,
- max_overflow=2,
+ pool_size=5,
+ max_overflow=10,
pool_pre_ping=POOL_PRE_PING,
pool_recycle=POOL_RECYCLE_SECONDS,
echo=False,
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 2caaf4a6f9..c506c7452e 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -54,10 +54,10 @@ class DatabaseManager:
# ----------------------------------------------------------------
# Pool class selection — see ADR-0004 (docs/decisions/0004-nullpool-for-sqlcipher.md)
#
- # We use a minimal QueuePool (pool_size=1, max_overflow=2) for
- # production and StaticPool for tests.
+ # We use QueuePool (pool_size=5, max_overflow=10) for production
+ # and StaticPool for tests.
#
- # Why minimal pool_size=1 instead of the default 10:
+ # Why pool_size=5 instead of the default 10:
#
# 1. SQLCipher + WAL mode can leak file handles when connections
# close out of open-order. Fewer pooled connections = fewer
@@ -73,6 +73,15 @@ class DatabaseManager:
# to release all pooled connections, preventing long-lived
# handles from accumulating over days of idle operation.
#
+ # Why pool_size=5 and not 1: inject_current_user() creates a
+ # QueuePool session on every request via g.db_session. With the
+ # UI polling /api/research/<id>/status every 1-2s plus other
+ # API calls and before_request middleware, pool_size=1
+ # (max_overflow=2, so 3 total) is easily exhausted — causing
+ # 30-second timeouts and PendingRollbackError cascades.
+ # pool_size=5 + max_overflow=10 (15 total) handles realistic
+ # concurrent request loads while staying conservative with FDs.
+ #
# Why not NullPool: SQLCipher's PRAGMA key adds ~0.2ms per
# connection open. With 20-30 queries per page load, NullPool
# adds a noticeable 4-6ms overhead vs QueuePool's ~1.5ms.
@@ -84,14 +93,14 @@ class DatabaseManager:
"""Get pool configuration kwargs based on pool type.
StaticPool doesn't support pool_size or max_overflow.
- QueuePool uses minimal sizing to limit FD usage.
- See ADR-0004 for rationale.
+ QueuePool uses moderate sizing to handle concurrent web requests
+ while limiting FD usage. See ADR-0004 for rationale.
"""
if self._use_static_pool:
return {}
return {
- "pool_size": 1,
- "max_overflow": 2,
+ "pool_size": 5,
+ "max_overflow": 10,
"pool_pre_ping": POOL_PRE_PING,
"pool_recycle": POOL_RECYCLE_SECONDS,
}