fix: close SQLite connections in delivery_ledger, async_delegation, and verification_evidence ledgers - #69785
Closed
JonthanaHanh wants to merge 1 commit into
Closed
Conversation
…nd verification_evidence ledgers All three ledger modules create a new sqlite3.Connection via _connect() on every call but rely on the context-manager protocol (with conn:) which only handles commit/rollback — it never calls conn.close(). Each call leaks one file descriptor; under sustained gateway or cron load the process hits the OS fd limit. Fix: wrap every _connect() call with contextlib.closing() so the connection is closed on scope exit, matching the pattern already used elsewhere in the codebase. Fixes NousResearch#69678 Fixes NousResearch#69567
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
All three ledger modules (
delivery_ledger.py,async_delegation.py,verification_evidence.py) create a newsqlite3.Connectionvia_connect()on every database call but rely on the context-manager protocol (with conn:) which only handles commit/rollback — it never callsconn.close(). Each call leaks one file descriptor; under sustained gateway or cron load the process hits the OS fd limit.Root Cause
sqlite3.Connection.__enter__returnsselfand__exit__callscommit()orrollback()but does not close the connection. Everywith _connect() as conn:block leaks a connection until GC runs (which is non-deterministic).Fix
Wrap every
_connect()call withcontextlib.closing()so the connection is explicitly closed on scope exit:Files Changed
gateway/delivery_ledger.py— 5 call sitestools/async_delegation.py— 13 call sitesagent/verification_evidence.py— 3 call sitesFixes
Fixes #69678
Fixes #69567