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.

docs: fix stale pool-size comments and NullPool references after #3441 (#3462)

LearningCircuit37a87297c361
diff --git a/docs/architecture.md b/docs/architecture.md
index f20881856b..6ef228467f 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -513,10 +513,11 @@ flowchart TD
I --> J["Worker @thread_cleanup:<br/>close worker DB session"]
J --> K["finally: search_engine.close()<br/>system.close() → strategy.close()"]
- K --> L["Main @thread_cleanup:<br/>close DB session, dispose engine"]
+ K --> L["Main @thread_cleanup:<br/>close DB session, return connection to pool"]
- subgraph sweep ["Defense-in-depth (independent 60s timer)"]
- M["Dead-thread sweep"] -.-> N["Dispose engines for<br/>dead thread IDs"]
+ subgraph sweep ["Defense-in-depth (independent timers)"]
+ M["Dead-thread credential sweep<br/>(~60s via processor_v2)"] -.-> N["Remove stale credentials<br/>for dead thread IDs"]
+ O["Pool dispose<br/>(30 min via connection_cleanup)"] -.-> P["engine.dispose() on all<br/>QueuePool engines"]
end
style sweep fill:#f0f0f0,stroke:#999
@@ -528,9 +529,8 @@ Each SQLCipher connection in WAL (Write-Ahead Logging) mode uses **2 file descri
| Component | FD Formula | With defaults |
|-----------|-----------|---------------|
-| QueuePool (steady state) | `logged_in_users × (pool_size × 2 + 1)` | `users × 21` FDs |
-| QueuePool (peak) | `logged_in_users × ((pool_size + max_overflow) × 2 + 1)` | `users × 81` FDs |
-| NullPool (background) | Transient — held for session lifetime only | Varies |
+| QueuePool (steady state) | `logged_in_users × (pool_size × 2 + 1)` | `users × 41` FDs |
+| QueuePool (peak) | `logged_in_users × ((pool_size + max_overflow) × 2 + 1)` | `users × 121` FDs |
Default Linux ulimit is 1024 soft (bare metal), which is tight for multi-user deployments. Docker's daemon default (typically 1M+) is adequate. QueuePool engines are created at login and disposed at logout, so only active users consume FDs.
@@ -540,11 +540,11 @@ For more on diagnosing FD exhaustion, see [Troubleshooting - Resource Exhaustion
| File | Role |
|------|------|
-| `src/local_deep_research/database/encrypted_db.py` | `DatabaseManager`, engine lifecycle, dead-thread sweep |
+| `src/local_deep_research/database/encrypted_db.py` | `DatabaseManager`, engine lifecycle, pool management |
| `src/local_deep_research/database/thread_local_session.py` | `@thread_cleanup` decorator, thread-local sessions, credential cleanup |
| `src/local_deep_research/web/app_factory.py` | `teardown_appcontext` handler, cleanup orchestration |
| `src/local_deep_research/web/services/research_service.py` | Research thread creation, `run_research_process()` |
-| `src/local_deep_research/web/queue/processor_v2.py` | Queue processing, dead-thread sweep trigger |
+| `src/local_deep_research/web/queue/processor_v2.py` | Queue processing, credential cleanup trigger |
### Areas for Improvement
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 940049a127..7321344a2c 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -596,7 +596,7 @@ lsof -p <PID> | grep -E '\.db|\.wal|\.shm'
**Solutions:**
-1. The app includes automatic dead-thread engine sweeps every ~60 seconds — this normally handles cleanup transparently
+1. The app includes automatic credential cleanup (~5 minutes) and periodic pool disposal (every 30 minutes) — this normally handles cleanup transparently
2. **Docker:** The daemon default FD limit (typically 1M+) is appropriate. Do not set a lower `nofile` ulimit — this was intentionally removed from `docker-compose.yml`
3. **Bare-metal Linux:** The default soft limit of 1024 may be too low. Increase it:
```bash
diff --git a/src/local_deep_research/database/encrypted_db.py b/src/local_deep_research/database/encrypted_db.py
index 00f826e494..bbb67f2208 100644
--- a/src/local_deep_research/database/encrypted_db.py
+++ b/src/local_deep_research/database/encrypted_db.py
@@ -46,12 +46,12 @@ class DatabaseManager:
self.has_encryption = self._check_encryption_available()
# ----------------------------------------------------------------
- # Pool class selection — see ADR-0004 (docs/decisions/0004-nullpool-for-sqlcipher.md)
+ # Pool class selection
#
- # We use QueuePool (pool_size=10, max_overflow=20) for production
+ # We use QueuePool (pool_size=20, max_overflow=40) for production
# and StaticPool for tests.
#
- # Why pool_size=10 (SQLAlchemy default):
+ # Why pool_size=20:
#
# 1. SQLCipher + WAL mode can leak file handles when connections
# close out of open-order. Fewer pooled connections = fewer
@@ -67,13 +67,13 @@ class DatabaseManager:
# to release all pooled connections, preventing long-lived
# handles from accumulating over days of idle operation.
#
- # Why pool_size=10 and not 1: inject_current_user() creates a
+ # Why pool_size=20 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=10 + max_overflow=20 (30 total) provides ample
+ # pool_size=20 + max_overflow=40 (60 total) provides ample
# headroom for concurrent requests and multiple browser tabs.
#
# Why not NullPool: SQLCipher's PRAGMA key adds ~0.2ms per
@@ -768,15 +768,6 @@ class DatabaseManager:
if not db_path.exists():
raise ValueError(f"No database found for user {username}")
- # Warn if this is a legacy database without per-database salt
- if self.has_encryption and not has_per_database_salt(db_path):
- logger.warning(
- f"Database for user '{username}' uses a legacy shared salt "
- f"(deprecated). For improved security, consider creating a new "
- f"account to get a per-database salt. Legacy databases remain "
- f"fully functional but are less resistant to multi-target attacks."
- )
-
with self._connections_lock:
engine = self.connections.get(username)
diff --git a/src/local_deep_research/web/auth/connection_cleanup.py b/src/local_deep_research/web/auth/connection_cleanup.py
index 2c223ff806..f6ac8c48f7 100644
--- a/src/local_deep_research/web/auth/connection_cleanup.py
+++ b/src/local_deep_research/web/auth/connection_cleanup.py
@@ -31,8 +31,7 @@ from ...web.routes.globals import get_usernames_with_active_research
# WHAT IT LOGS:
# - open_fds: total open file descriptors for the process
# - pool_engines: number of per-user QueuePool engines
-# - thread_engines: number of per-thread NullPool engines (should be 0
-# when idle — nonzero means @thread_cleanup didn't fire)
+# - pool_checked_out: connections currently checked out from QueuePool
# - protected_users: users with active sessions
#
# HOW TO USE: grep "Resource monitor" in container logs. If open_fds
@@ -126,10 +125,8 @@ def cleanup_idle_connections(session_manager, db_manager):
f"closed {closed}, protected {len(protected)} active user(s)"
)
- # Sweep dead-thread engines and sessions — safety net when neither HTTP
- # requests nor the queue processor are triggering sweeps.
- # Engine sweep is rate-limited internally (at most once per 60s);
- # session sweep runs unconditionally but is lightweight.
+ # Sweep dead-thread sessions and credentials — safety net when neither
+ # HTTP requests nor the queue processor are triggering sweeps.
cleanup_dead_threads()
# --- Periodic pool dispose to release WAL/SHM handles ---
diff --git a/src/local_deep_research/web/queue/processor_v2.py b/src/local_deep_research/web/queue/processor_v2.py
index a7ae89fbbc..eda57fadbe 100644
--- a/src/local_deep_research/web/queue/processor_v2.py
+++ b/src/local_deep_research/web/queue/processor_v2.py
@@ -435,8 +435,8 @@ class QueueProcessorV2:
logger.exception("Error in queue processor loop")
finally:
# Clean up thread-local database session after each iteration.
- # This long-running daemon thread repeatedly opens NullPool engines
- # via get_user_db_session(); without cleanup, FDs accumulate.
+ # The loop opens a new session each iteration via get_user_db_session();
+ # closing it returns the connection to the shared QueuePool promptly.
try:
from ...database.thread_local_session import (
cleanup_current_thread,