fix: await rollback in dry-run transactions#291
Merged
Conversation
trx.rollback() was fired without awaiting, so withTransaction could resolve (and the CLI could process.exit) before the ROLLBACK actually completed against the database. Add a regression test covering the ordering.
There was a problem hiding this comment.
Pull request overview
This PR fixes dry-run transaction handling in withTransaction() by awaiting the rollback operation, preventing a floating rollback promise and improving correctness of async ordering and error propagation in dry-run mode.
Changes:
- Await
trx.rollback()in the dry-run path ofwithTransaction()to avoid unhandled rejections and ensure deterministic completion ordering. - Add unit tests covering rollback-await ordering, no-commit behavior in dry-run, and callback error propagation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/util/db.ts |
Awaits dry-run rollback to ensure the rollback promise is properly handled before returning. |
test/unit/util/db.test.ts |
Adds unit tests validating dry-run rollback ordering and behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
91
to
95
| const trx = await db.connection.transaction(); | ||
| const res = await callback(trx); | ||
|
|
||
| trx.rollback(); | ||
| await trx.rollback(); | ||
|
|
Kushalkhadka7
approved these changes
Jul 23, 2026
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
withTransaction()insrc/util/db.tsruns the dry-run path by opening a transaction, running the callback, then rolling back so nothing is committed.trx.rollback()was called withoutawait, i.e. a floating promise.commit()is never called on this path, so nothing becomes durable regardless of rollback timing; and if the connection drops before an explicitROLLBACKis processed, the DB server itself aborts any open transaction on disconnect. The actual risks of the floating promise are:rollback()itself rejects (e.g. connection already dropped), nothing awaits/catches it. There's no globalunhandledRejectionhandler in this codebase, and Node 15+ terminates the process by default on an unhandled rejection — so a transient rollback error could crash the CLI with a misleading error after the dry run had already succeeded.'END: Dry Run transaction rolled back successfully'was logged before rollback was confirmed to have completed.process.exit) in a longer-lived process — the connection isn't guaranteed released back to the pool by the timewithTransactionresolves.await trx.rollback()so the promise is properly awaited (and any rejection is attached to the returned promise chain) beforewithTransactionresolves.test/unit/util/db.test.tscovering the await ordering (fails against the previous unawaited code), that no commit ever happens in dry-run, and that callback errors still propagate.Test plan
yarn test:unit— 88 passing, including 3 new tests inUTIL: dbyarn lint— passing