fix: close leaked SQLite connections in delivery, delegation, verification, and cron execution ledgers - #70985
Merged
Merged
Conversation
…, delegation, and verification ledgers Three durable ledgers used `with _connect() as conn:` where the sqlite3 connection context manager commits/rolls back but never closes, leaking the db/-wal/-shm file descriptors on every call. On a long-running gateway this exhausts RLIMIT_NOFILE and fails unrelated components with `[Errno 24] Too many open files`. Same bug class as the cron execution ledger (#69567 / PR #69594), which the connection helpers here are modeled on. Fix: route every ledger operation through a `_transaction()` context manager that guarantees `conn.close()` on exit. `_connect()` keeps its schema-on-connect contract (several tests call it directly) and now self-closes if schema init fails. Adds per-module regression tests asserting every opened connection is closed, including the no-op-update and exception-mid-transaction paths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sibling of the #69678/#69567 ledger leak class found while widening the sweep: _probe_state_db used 'with sqlite3.connect(...)', whose context manager only commits/rolls back and never closes, leaking one connection (db fd) per health poll in the long-running gateway. Wrap the connection in contextlib.closing so every probe closes deterministically.
Contributor
૮ >ﻌ< ა ci reviewran on 672dd0d all good! |
This was referenced Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Long-running gateway and cron processes no longer leak one SQLite fd per ledger operation — connections in delivery_ledger, async_delegation, verification_evidence, the cron executions ledger, and the gateway readiness probe now close deterministically.
Changes
Validation
Targeted ledger/cron suites green; fd-count regression tests assert no growth across repeated operations.
Supersedes #69785, #70530, #70918, #70917 (duplicates of the two base PRs).
Fixes #69678
Fixes #69567
Infographic