crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.47k stars 763 forks source link

Successful connection doesn't reset the exponential backoff state #1597

Open afk11 opened 1 year ago

afk11 commented 1 year ago

When I kill crossbar, I can see python-autobahn doing exponential backoff which is fine, however, if the connection re-establishes, the existing state isn't cleared. So if there is a subsequent disconnect, instead of the retry_delay being 0, it continues to grow the previous retry delay

In these circumstances, small outages cause the retry_delay to accumulate, building up to a 5+ minute wait before it even attempts a connection

I'm looking into how I can reach this from the Component, or if changes need to be made to the library, but I wanted to open this in case anyone has feedback or a workaround

Thanks in advance

afk11 commented 1 year ago

It looks like I want to call _Transport.reset() which would reset self.retry_delay = self.initial_retry_delay

https://github.com/crossbario/autobahn-python/blob/master/autobahn/wamp/component.py#L302

meejah commented 1 year ago

I agree that the autobahn infrastructure itself should reset the delay after a successful connect.

One workaround meanwhile could be to set max_retry_delay to something lower than the default (which is 300 seconds).

If you wanted to try to prepare a fix, I believe the right place to call transport.reset() would be somewhere in this "else" clause when the session is set up: https://github.com/crossbario/autobahn-python/blob/master/autobahn/wamp/component.py#L763 (although it's been a while since I've looked at this code).