tests: close leaked sqlite connections — ResourceWarning flood in CI test job #618

Closed
opened 2026-08-14 00:19:15 +00:00 by kert · 1 comment
Owner

CI's test job (e.g. run 773 jobstep 5) floods ResourceWarning: unclosed database in <sqlite3.Connection> + Enable tracemalloc… hint lines — read as crash noise, actually GC'd never-closed connections. Full-suite repro (14,099 passed, 25m36s, exit 0 — no hang) attributes 38 warnings to:

  • src/zot/db.py:772 — 4× unclosed connections (zot module close path)
  • tests/zot/ — test_extract.py::TestExtractorRealDb::test_export_provenance_real (4×), test_duck.py:242, test_db.py:157, test_ops.py::TestFixKeys::test_runs
  • tests/api/test_server.py (Auth + Pipelines, 2× each) and test_routes_coverage.py (2× each)
  • tests/cli/test_llm_exercise.py ::TestIndexComments::test_default_collection_is_comments (2×) — Store opened without close (touched by #595)
  • tests/rec/test_main.py, tests/aco/test_dag.py (1× each); plus coverage's own sqlitedb.py (xdist artifact, upstream)

Fix: close/context-manage every connection (fixtures + zot db paths); then gate regressions with filterwarnings = ["error::ResourceWarning", "ignore::ResourceWarning:coverage.*"] in pyproject if the suite stays green under it — otherwise document why not.

CI's test job (e.g. run 773 jobstep 5) floods `ResourceWarning: unclosed database in <sqlite3.Connection>` + `Enable tracemalloc…` hint lines — read as crash noise, actually GC'd never-closed connections. Full-suite repro (14,099 passed, 25m36s, exit 0 — no hang) attributes 38 warnings to: - [`src/zot/db.py:772`](https://git.fhirworx.io/homelab/stack/src/branch/main/src/zot/db.py#L772) — 4× unclosed connections (zot module close path) - `tests/zot/` — `test_extract.py::TestExtractorRealDb::test_export_provenance_real` (4×), `test_duck.py:242`, `test_db.py:157`, `test_ops.py::TestFixKeys::test_runs` - `tests/api/test_server.py` (Auth + Pipelines, 2× each) and `test_routes_coverage.py` (2× each) - [`tests/cli/test_llm_exercise.py`](https://git.fhirworx.io/homelab/stack/src/branch/main/tests/cli/test_llm_exercise.py) `::TestIndexComments::test_default_collection_is_comments` (2×) — Store opened without close (touched by #595) - `tests/rec/test_main.py`, `tests/aco/test_dag.py` (1× each); plus coverage's own `sqlitedb.py` (xdist artifact, upstream) Fix: close/context-manage every connection (fixtures + zot db paths); then gate regressions with `filterwarnings = ["error::ResourceWarning", "ignore::ResourceWarning:coverage.*"]` in pyproject if the suite stays green under it — otherwise document why not.
kert added the quality label 2026-08-14 00:19:15 +00:00
Author
Owner

Fixed in cc418ce. Four tracemalloc-verified leaks closed (zot Db.init on schema-parity raise; two zot test fixtures; cli comments lookup-cache connection) — most of this issue's per-test attributions were GC-timing misattribution across xdist workers. Gate landed: filterwarnings = ["error::ResourceWarning", "ignore::ResourceWarning:coverage.*"]; the commit's pre-commit hook ran the full suite green under the gate. Scoped tracemalloc reruns: 0 ResourceWarnings (was 22+ in tests/zot alone). The unrelated live-data failure surfaced en route is tracked as #623. Report: [.superpowers/sdd/p618-report.md] (session artifact).

Fixed in cc418ce. Four tracemalloc-verified leaks closed (zot Db.__init__ on schema-parity raise; two zot test fixtures; cli comments lookup-cache connection) — most of this issue's per-test attributions were GC-timing misattribution across xdist workers. Gate landed: `filterwarnings = ["error::ResourceWarning", "ignore::ResourceWarning:coverage.*"]`; the commit's pre-commit hook ran the full suite green under the gate. Scoped tracemalloc reruns: 0 ResourceWarnings (was 22+ in tests/zot alone). The unrelated live-data failure surfaced en route is tracked as #623. Report: [`.superpowers/sdd/p618-report.md`] (session artifact).
kert closed this issue 2026-08-14 15:10:50 +00:00
Sign in to join this conversation.