fix: close SQLite connections in 3 ledgers (delivery_ledger, async_delegation, verification_evidence) - #70918
Closed
kshitijk4poor wants to merge 1 commit into
Closed
Conversation
…erification_evidence (NousResearch#69678) Add _transaction() context manager that guarantees conn.close() on exit, matching the accepted fix pattern from NousResearch#69567 (kanban_db.connect_closing). Root cause: sqlite3.Connection.__exit__ only commits/rollbacks; it does NOT close the file descriptor. In long-lived processes every _connect() call leaked an FD, accumulating until RLIMIT_NOFILE exhaustion. Changes: - Add _transaction() context manager to all 3 modules with guaranteed conn.close() on exit (commit on success, rollback on exception). - Replace every with _connect() as conn: with with _transaction() as conn: (5 sites in delivery_ledger.py, 13 in async_delegation.py, 3 in verification_evidence.py). - Add 2 connection-closing regression tests per test suite (normal exit + exception path). Fixes NousResearch#69678
Collaborator
Contributor
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
Fixes SQLite connection FD leaks in 3 ledgers that exhaust
RLIMIT_NOFILEin long-running gateway processes.Changes
gateway/delivery_ledger.py: Add_transaction()context manager that guaranteesconn.close()— replaces 5with _connect() as conn:sitestools/async_delegation.py: Same fix — replaces 13 leak sitesagent/verification_evidence.py: Same fix — replaces 3 leak sitesRoot cause
sqlite3.Connection.__exit__only commits/rollbacks; it does NOT close the FD. Every operation opened a connection that was never closed, accumulating until[Errno 24] Too many open files.Fixes #69678.
Salvaged from @webtecnica's PR #70530 (commit 3 of 3).
Validation