aio-pika icon indicating copy to clipboard operation
aio-pika copied to clipboard

RobustConnection (re)connect tasks are impossible to stop

Open tilsche opened this issue 3 years ago • 0 comments

This is related to #279. To implement a reconnect timeout from the outside, we use a watchdog doing await RobustConnection.close() after a reconnect timeout. But that doesn't actually do anything to the ongoing loop in RobustConnection.connect() (spawned by reconnect()). There are several issues with this:

  • You can't get out of this loop except for ugly workarounds (forcing fail_fast=True).
  • There is no handle to this task running in the loop completely detached:
    • It is impossible to cancel this particular task
    • It is impossible to handle exceptions properly - so if we force it to stop somehow, there will always be a "Task exception was never retrieved"-error

I would suggest that RobustConnection keeps track of reconnect() tasks and cleanly cancel() them in close().

I'm happy to help with a PR if the general direction would be acceptable.

While this constitutes an independent improvement. Issue #279 / PR #247 would still be great to have.

tilsche avatar Sep 25 '21 11:09 tilsche