fix: treat pgx "conn closed" as sql.ErrTxDone#20
Conversation
|
Warning Rate limit exceeded
To continue reviewing without waiting, purchase usage credits in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughThe PR modifies ChangesConnection Rollback Error Handling
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@connection.go`:
- Around line 179-182: The rollback error check currently calls dberr.Error()
without ensuring dberr is non-nil; change the logic in the rollback/error
handling block (variables dberr and err) to first test if dberr != nil before
inspecting its message (e.g., strings.Contains(dberr.Error(), "conn closed")),
and only then return the appropriate error; ensure you preserve returning the
original err when rollback succeeded (dberr == nil) and avoid calling Error() on
a nil dberr.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
There was a problem hiding this comment.
Pull request overview
This PR adjusts transaction rollback error handling to avoid test flakes when using the pgx driver, by treating a "conn closed" rollback error as a symptom (similar to sql.ErrTxDone) and returning the original inner error instead.
Changes:
- In
Connection.Transaction, add a special-case for rollback errors containing"conn closed"(pgx) to return the original error from the transaction body. - Preserve existing behavior that treats
sql.ErrTxDoneduring rollback as non-actionable and returns the original error.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This fixes an annoying flake in tests.
Summary by CodeRabbit