Conversation
8f33703 to
893024e
Compare
There was a problem hiding this comment.
Pull request overview
Adds regression coverage and hardens RobustConnection’s reconnection loop to address cases where reconnection can silently stop after a “stuck” connection (issue #669).
Changes:
- Add new proxy-based integration tests around reconnect behavior and consumer iteration across reconnects.
- Make
_on_connection_close()resilient to exceptions thrown by close callbacks so the reconnect loop is always woken. - Add explicit
asyncio.CancelledErrorhandling in the connection factory loop to avoid unexpected task death during reconnect attempts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/test_amqp_robust_proxy.py |
Adds new reconnect-focused integration tests (stuck/heartbeat scenario + queue iterator across reconnect). |
aio_pika/robust_connection.py |
Improves reconnect-loop resilience by guarding close callbacks and handling CancelledError during connection attempts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Alviner
previously approved these changes
Feb 21, 2026
The merge-base changed after approval.
decaz
previously approved these changes
Feb 22, 2026
The merge-base changed after approval.
3a5ef82 to
b2d7d40
Compare
decaz
approved these changes
Feb 22, 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.
Fixes #669
The root cause was two resilience gaps in
RobustConnection's reconnection path.How stuck connection detection works:
aiormq's heartbeat monitor detects no frames received within the grace timeout, cancels the reader task, and the resultingCancelledErrorpropagates throughaiormq's closing future intoRobustConnection._on_connection_close(), which should set an internal event to wake the reconnection loop.Gap 1:
_on_connection_closenot resilient to callback exceptions. Ifclose_callbacks(exc)(called viasuper()._on_connection_close()) raised any exception,__connection_close_event.set()was never reached. The reconnection factory loop never woke up, and the connection was permanently dead.Gap 2:
__connection_factorydidn't handleasyncio.CancelledError. In Python 3.9+,CancelledErroris aBaseException, so it's not caught by exceptCONNECTION_EXCEPTIONSorexcept Exception. IfCancelledErrorwas raised during a reconnection attempt (e.g. fromaiormqcleanup interacting with the new connection), the factory task would crash silently and reconnection would stop permanently.Fix: Wrapped the
super()._on_connection_close()call in try/except so the reconnection event is always set, and added explicitCancelledErrorhandling in the connection factory loop so it retries instead of crashing.