feat: fail fast on unrecoverable auth errors during reconnect - #22
Conversation
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughReconnection now stops on permanent authentication or authorization failures, reports terminal errors through ChangesReconnect error handling
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Connection
participant RabbitMQ
participant OnDisconnect
Connection->>RabbitMQ: attempt reconnect
RabbitMQ-->>Connection: dial result
Connection->>Connection: classify permanent error
Connection->>OnDisconnect: terminal error or ErrMaxReconnects
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 `@rabbitmq.go`:
- Around line 341-343: Protect all three onDisconnect invocation sites in
handleReconnect from panics and blocking callback execution, while preserving
the documented before-reconnection ordering. Add a safeOnDisconnect helper that
recovers callback panics and invoke it instead of calling onDisconnect directly
at each site; ensure the reconnect loop can still observe closeCh without an
unbounded user callback blocking it.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 023b050a-4f70-45ba-a0c2-b5756e53ab34
📒 Files selected for processing (5)
CHANGELOG.mdREADME.mdconfig_test.gointegration_test.gorabbitmq.go
When a reconnection dial is rejected for bad credentials, an unusable SASL mechanism, or no vhost access (AMQP 403 AccessRefused / 530 NotAllowed), handleReconnect now surfaces the error via OnDisconnect and stops instead of backing off and re-submitting the same rejected parameters forever. Transient failures (network errors, 320 ConnectionForced from a broker restart) keep retrying with the existing exponential backoff. Classification is by AMQP reply code, not amqp.Error.Recoverable(): the dial-time auth sentinels (ErrCredentials, ErrSASL, ErrVhost) are struct literals whose Recover field is false, so Recoverable() reports false for exactly these errors. Dial errors are now wrapped with %w so callers can errors.As them to *amqp.Error; errors.Is(err, ErrConnectionClosed) still matches. OnDisconnect now fires on any terminal give-up: both the auth abort and the pre-existing MaxReconnectAttempts-exhausted path invoke it once more with the terminal error (a *amqp.Error, or the previously-unused ErrMaxReconnects sentinel), so a permanently dead connection is observable, not just logged. Hardening of the OnDisconnect path: - A clean broker close delivers a nil *amqp.Error, which as an interface value is non-nil but panics when a handler calls err.Error(); it is normalized to ErrConnectionClosed before the callback runs. - All callback invocations are routed through safeOnDisconnect, which recovers and logs a panicking callback instead of letting it crash the reconnect goroutine (and the process). Callbacks remain synchronous to preserve the documented before-reconnection ordering. Bumps amqp091-go to v1.13.0 (data-race, ack, and TLS/SASL hardening fixes consumed transparently). Verified with -race unit tests and the full integration suite on RabbitMQ 4 and 3.13.
73611b9 to
44b6ba5
Compare
When a reconnection dial is rejected for bad credentials, an unusable SASL mechanism, or no vhost access (AMQP 403 AccessRefused / 530 NotAllowed), handleReconnect now surfaces the error via OnDisconnect and stops instead of backing off and re-submitting the same rejected parameters forever. Transient failures (network errors, 320 ConnectionForced from a broker restart) keep retrying with the existing exponential backoff.
Classification is by AMQP reply code, not amqp.Error.Recoverable(): the dial-time auth sentinels (ErrCredentials, ErrSASL, ErrVhost) are struct literals whose Recover field is false, so Recoverable() reports false for exactly these errors. Dial errors are now wrapped with %w so callers can errors.As them to *amqp.Error; errors.Is(err, ErrConnectionClosed) still matches.
OnDisconnect now fires on any terminal give-up: both the auth abort and the pre-existing MaxReconnectAttempts-exhausted path invoke it once more with the terminal error (a *amqp.Error, or the previously-unused ErrMaxReconnects sentinel), so a permanently dead connection is observable, not just logged.
Also fixes a pre-existing latent panic: a clean broker close delivers a nil *amqp.Error, which as an interface value is non-nil but panics when a handler calls err.Error(); it is now normalized to ErrConnectionClosed before the callback runs.
Bumps amqp091-go to v1.13.0 (data-race, ack, and TLS/SASL hardening fixes consumed transparently). Verified with -race unit tests and the full integration suite on RabbitMQ 4 and 3.13.
Summary
Motivation
Fixes #
Changes
Checklist
make all)Summary by CodeRabbit
Bug Fixes
OnDisconnectnow reports terminal authentication errors and exhausted reconnect attempts.ErrConnectionClosedinstead of an invalid nil error.Documentation
OnDisconnectcallback outcomes.