Dispose DB engine in CLI to fix Python 3.13 ResourceWarning leak#130
Merged
Conversation
The `rcdb run` CLI test test_number_shortcut_equals_run (added in 876e2a5) fails only on Python 3.13: it asserts that `rcdb 1000` and `rcdb run 1000` produce identical captured output, but Python 3.13 emits `ResourceWarning: unclosed database` for the leaked SQLite connection at GC time, and Click's CliRunner folds stderr into the captured output, so the warning non-deterministically pollutes one of the two runs. Root cause: the CLI never disconnected its lazily-created RCDBProvider, and `disconnect()` only closed the ORM session, never disposing the engine - so the pooled DBAPI connection stayed open until garbage collection. - provider.disconnect(): also dispose the engine so the connection pool releases its DBAPI connections (null-safe). - app_context: add close() to tear down the provider. - cli/app: register ctx.call_on_close(close) so every command disposes the engine deterministically instead of relying on GC. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SeseguLYWWEBNUZc2Fq4j9
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.
The
rcdb runCLI test test_number_shortcut_equals_run (added in 876e2a5)fails only on Python 3.13: it asserts that
rcdb 1000andrcdb run 1000produce identical captured output, but Python 3.13 emits
ResourceWarning: unclosed databasefor the leaked SQLite connection at GCtime, and Click's CliRunner folds stderr into the captured output, so the
warning non-deterministically pollutes one of the two runs.
Root cause: the CLI never disconnected its lazily-created RCDBProvider, and
disconnect()only closed the ORM session, never disposing the engine - sothe pooled DBAPI connection stayed open until garbage collection.
releases its DBAPI connections (null-safe).
engine deterministically instead of relying on GC.
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01SeseguLYWWEBNUZc2Fq4j9