Skip to content

fix: treat pgx "conn closed" as sql.ErrTxDone#20

Merged
zepatrik merged 2 commits into
mainfrom
fix/dont-attempt-rollback-ctx-canceled
May 7, 2026
Merged

fix: treat pgx "conn closed" as sql.ErrTxDone#20
zepatrik merged 2 commits into
mainfrom
fix/dont-attempt-rollback-ctx-canceled

Conversation

@zepatrik

@zepatrik zepatrik commented May 7, 2026

Copy link
Copy Markdown
Member

This fixes an annoying flake in tests.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for failed database transactions when connections are unexpectedly closed. The system now returns the original error instead of a secondary rollback error, providing clearer error reporting.

Copilot AI review requested due to automatic review settings May 7, 2026 11:13
@zepatrik zepatrik requested a review from a team as a code owner May 7, 2026 11:13
@coderabbitai

coderabbitai Bot commented May 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@zepatrik has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 56 minutes and 53 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 82f98b1f-8d59-4871-9db0-55720128cd17

📥 Commits

Reviewing files that changed from the base of the PR and between 10be7a3 and 33c9bf6.

📒 Files selected for processing (1)
  • connection.go
📝 Walkthrough

Walkthrough

The PR modifies Connection.Transaction's error handling to preserve the original transaction error when rollback fails with a connection-closed error, preventing rollback failures from masking the primary transactional outcome.

Changes

Connection Rollback Error Handling

Layer / File(s) Summary
Rollback Error Handling
connection.go
Rollback error handling now checks if the error message contains "conn closed" and returns the original transaction error instead of the rollback error.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • ory/pop#19: Both PRs modify Connection.Transaction's rollback-error handling to preserve and return the original transaction error, avoiding secondary rollback/reporting errors.

Suggested reviewers

  • gaultier
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: treating pgx 'conn closed' errors like sql.ErrTxDone in transaction handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dont-attempt-rollback-ctx-canceled

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7848bd46-2727-4800-be9c-b181033facc4

📥 Commits

Reviewing files that changed from the base of the PR and between 5dbeab0 and 10be7a3.

📒 Files selected for processing (1)
  • connection.go

Comment thread connection.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ErrTxDone during rollback as non-actionable and returns the original error.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread connection.go Outdated
@zepatrik zepatrik enabled auto-merge (squash) May 7, 2026 11:54
@zepatrik zepatrik disabled auto-merge May 7, 2026 16:12
@zepatrik zepatrik merged commit 8912655 into main May 7, 2026
9 checks passed
@zepatrik zepatrik deleted the fix/dont-attempt-rollback-ctx-canceled branch May 7, 2026 16:12
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.

2 participants