fix: worker-thread DB-connection hygiene (ADR-0021) #33
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.37) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 238 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.328
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #33"
general
weight: 0.35
BenA-SA
What
The last of the three deferred items: sync tools run in the SDK's anyio thread pool (
anyio.to_thread.run_sync, no wrapper seam), so ORM connections open in threads Django'srequest_finishedcleanup never reaches — never aged out (CONN_MAX_AGE), never health-checked, never closed. A slow stale-connection leak that surfaces asserver closed the connection unexpectedlyafter DB restarts/idle timeouts, under exactly the sustained load this package is built for.How
After each buffered dispatch the view runs Django's own
close_old_connectionsinside the pool (await anyio.to_thread.run_sync(close_old_connections)):CONN_MAX_AGE=0closes the tool's connection; positive ages persist + health-check on Django's schedule.request_finished.Testing + Inspector infrastructure
AnyIO worker thread— and fails on the pre-fix code. (The closing itself is unobservable under pytest: Django deliberately never closes in-memory SQLite test connections; noted in the test and ADR.)db_thread_info— callcount_usersthen it in Inspector against the file-backed demo and the reused worker thread reportsconnection_open=Falselive.Joins the unreleased 0.1.4 changelog. ADR-0021 records the LIFO reasoning, the
CONN_MAX_AGE>0caveat, and the upstream-hook ask that would make this exact instead of probabilistic.