fix: roll back InsertImage transaction when related clears fail#69
Open
Abhineshhh wants to merge 3 commits into
Open
fix: roll back InsertImage transaction when related clears fail#69Abhineshhh wants to merge 3 commits into
Abhineshhh wants to merge 3 commits into
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
maniSbindra
requested changes
Jul 13, 2026
maniSbindra
left a comment
Member
There was a problem hiding this comment.
Thanks for the issue and this PR. A minor comment after which we will be good to merge.
Member
|
Thanks @Abhineshhh, Could you enable commit signing and re-push? |
The related-table DELETE loop used `if _, err := tx.Exec(...)`, which shadowed the outer err watched by deferred rollback. On clear failure the function returned an error but left the transaction open, which can leak the sole SQLite connection (MaxOpenConns=1). Use a named result err and assign with `=` so every failure path triggers rollback.
Defer runs only after Begin succeeds, so tx is always set. Remove the dead tx != nil guard and the comment that described an unreachable path.
959eec0 to
f287a71
Compare
maniSbindra
approved these changes
Jul 14, 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
InsertImageso failures while clearing related tables always roll back the transactionif _, err := tx.Exec(...)shadowed the outererrwatched by deferred rollbackerr, assign with=, and guard rollback whentxis nilMaxOpenConns(1)proving rollback + connection reuse after clear failureFixes #67
Test plan
go test ./pkg/infrastructure/database/ -count=1TestInsertImage_RollbackOnClearFailure