Repository navigation
fix(ncps): close dbClient on shutdown; use FORCE drop in tests - #1243
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughThis PR improves database resource cleanup in two ways: the PostgreSQL test database drop function now forces disconnection using ChangesDatabase client cleanup and test database maintenance
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
|
This change is part of the following stack:
Change managed by git-spice. |
There was a problem hiding this comment.
Code Review
This pull request introduces explicit database client shutdown registration across several commands (fsck, migrate_nar_to_chunks, migrate_narinfo, and serve) to mitigate connection leaks. Additionally, the PostgreSQL cleanup script is updated to use 'DROP DATABASE ... WITH (FORCE)' to prevent blocking during test teardown. Feedback suggests evaluating whether these lifecycle management changes, which primarily benefit the testing environment, should be scoped differently or extended to other components like the cache and HTTP server.
6df6ab4 to
abf4c46
Compare
411ed9e to
743ec78
Compare
abf4c46 to
f807885
Compare
743ec78 to
0d81c5c
Compare
f807885 to
ee204a9
Compare
0d81c5c to
6aacbc7
Compare
ee204a9 to
f3627df
Compare
d0524aa to
4a6c1a2
Compare
Found while shrinking the integration-test wall time. Every ncps
subcommand (serve, fsck, migrate-narinfo, migrate-nar-to-chunks)
opens a *database.Client via createDatabaseClient but never registers
its Close in the cli After-hook. In production the process just
exits so it's invisible; in tests the connection pool lingers, and
every integration-test cleanup paid a flat ~5s waiting for
DROP DATABASE to drain the leaked connections.
Quantified impact (full integration run, all deps live):
- pkg/ncps total: 23.07s -> 6.28s
- 18 TestFsckBackends/PostgreSQL/CDC/* tests all dropped off the
"elapsed > 500ms" list (was uniformly ~5s each).
- Cumulative `go test -race ./...` with integration backends:
80.09s -> 64.40s (~20% reduction in this commit alone).
Changes:
- pkg/ncps/{fsck,serve,migrate_narinfo,migrate_nar_to_chunks}.go:
register `dbClient.Close` as a shutdown function right after
createDatabaseClient. Captured by closure so the body of the
Action continues to use the same client; After-hook calls Close
in parallel with otelShutdown via wg.Go.
- nix/process-compose/postgres-dblink-create-drop-functions.sql:
drop_test_db now issues `DROP DATABASE ... WITH (FORCE)` (PG 13+)
as a belt-and-braces measure in case any future test still leaks
a connection past Close. The Go-side fix above is the actual
reason the per-test wait disappeared.
Also captures the integration timings before and after this commit
under openspec/changes/less-tests/integration-*-timings.txt.
Verified: `go test -race` on every touched package passes;
\`golangci-lint run\` is clean. The applied SQL function update was
also run against the live PG instance by hand so subsequent local
runs immediately benefit.
4a6c1a2 to
a13d438
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1243 +/- ##
=====================================
Coverage 5.50% 5.50%
=====================================
Files 6 6
Lines 400 400
=====================================
Hits 22 22
Misses 374 374
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Found while shrinking the integration-test wall time. Every ncps
subcommand (serve, fsck, migrate-narinfo, migrate-nar-to-chunks)
opens a *database.Client via createDatabaseClient but never registers
its Close in the cli After-hook. In production the process just
exits so it's invisible; in tests the connection pool lingers, and
every integration-test cleanup paid a flat ~5s waiting for
DROP DATABASE to drain the leaked connections.
Quantified impact (full integration run, all deps live):
"elapsed > 500ms" list (was uniformly ~5s each).
go test -race ./...with integration backends:80.09s -> 64.40s (~20% reduction in this commit alone).
Changes:
register
dbClient.Closeas a shutdown function right aftercreateDatabaseClient. Captured by closure so the body of the
Action continues to use the same client; After-hook calls Close
in parallel with otelShutdown via wg.Go.
drop_test_db now issues
DROP DATABASE ... WITH (FORCE)(PG 13+)as a belt-and-braces measure in case any future test still leaks
a connection past Close. The Go-side fix above is the actual
reason the per-test wait disappeared.
Also captures the integration timings before and after this commit
under openspec/changes/less-tests/integration-*-timings.txt.
Verified:
go test -raceon every touched package passes;`golangci-lint run` is clean. The applied SQL function update was
also run against the live PG instance by hand so subsequent local
runs immediately benefit.