Skip to content

Dispose DB engine in CLI to fix Python 3.13 ResourceWarning leak#130

Merged
DraTeots merged 1 commit into
mainfrom
claude/ci-failure-investigation-blw13n
Jun 25, 2026
Merged

Dispose DB engine in CLI to fix Python 3.13 ResourceWarning leak#130
DraTeots merged 1 commit into
mainfrom
claude/ci-failure-investigation-blw13n

Conversation

@DraTeots

Copy link
Copy Markdown
Collaborator

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

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
@DraTeots DraTeots merged commit b30819e into main Jun 25, 2026
17 checks passed
@DraTeots DraTeots deleted the claude/ci-failure-investigation-blw13n branch June 25, 2026 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants