Skip to content

fix(cli): release database connections after commands#26

Merged
3m1n3nc3 merged 2 commits into
mainfrom
fix/cli-release-db-connections
Jul 5, 2026
Merged

fix(cli): release database connections after commands#26
3m1n3nc3 merged 2 commits into
mainfrom
fix/cli-release-db-connections

Conversation

@3m1n3nc3

@3m1n3nc3 3m1n3nc3 commented Jul 5, 2026

Copy link
Copy Markdown
Member

The CLI never tore down the database driver, so after migrate/seed/etc. finished the pg connection pool kept the Node event loop alive and the process hung for seconds (up to the pool's idle/keepalive timeout) before exiting.

  • Add an optional dispose() to the DatabaseAdapter contract. The Kysely adapter destroys its Kysely instance (ending the pool); the Prisma compatibility adapter calls $disconnect().
  • Add disposeArkormRuntime(): tears down the configured adapter and/or client (Prisma $disconnect, Kysely destroy, or a bare pool end), avoiding double-closing a client an adapter already owns, and swallowing teardown errors during shutdown.
  • The CLI entrypoint drains the runtime in a finally after every command, so it exits promptly.

Tests: unit coverage for disposeArkormRuntime resolution + a postgres e2e asserting the pool is actually ended (pool.ended) after dispose.

The CLI never tore down the database driver, so after migrate/seed/etc.
finished the pg connection pool kept the Node event loop alive and the
process hung for seconds (up to the pool's idle/keepalive timeout) before
exiting.

- Add an optional dispose() to the DatabaseAdapter contract. The Kysely
  adapter destroys its Kysely instance (ending the pool); the Prisma
  compatibility adapter calls $disconnect().
- Add disposeArkormRuntime(): tears down the configured adapter and/or client
  (Prisma $disconnect, Kysely destroy, or a bare pool end), avoiding
  double-closing a client an adapter already owns, and swallowing teardown
  errors during shutdown.
- The CLI entrypoint drains the runtime in a finally after every command, so
  it exits promptly.

Tests: unit coverage for disposeArkormRuntime resolution + a postgres e2e
asserting the pool is actually ended (pool.ended) after dispose.
@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/helpers/runtime-config.ts 73.33% 4 Missing ⚠️
src/adapters/PrismaDatabaseAdapter.ts 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@3m1n3nc3 3m1n3nc3 merged commit e1ad156 into main Jul 5, 2026
6 checks passed
@3m1n3nc3 3m1n3nc3 deleted the fix/cli-release-db-connections branch July 5, 2026 08:30
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.

1 participant