isra17 / autobahn-autoreconnect

Python Autobahn runner with auto-reconnect feature
GNU General Public License v2.0
19 stars 10 forks source link

Reconnect Issue #19

Closed webCoderLOL closed 7 years ago

webCoderLOL commented 7 years ago

Hi,

The reconnect functionality seems to be working in certain condition. Maybe I am missing some configurations. I can see ApplicationRunner try to reconnect when it fails initially

my stdout

Connection failed
Retry in 0.5 seconds
Connection failed
Retry in 1 seconds

which is awesome. However, if the network connection drops in the middle of operation, it doesn't seem to kick start the _reconnect() function again. I don't see

Connection lost
Reconnecting

in my stdout. Here is my code

from autobahn_autoreconnect import ApplicationRunner, BackoffStrategy

class ISIBackoffStrategy(BackoffStrategy):
    '''
    retry incremental 0.5, 1, 2. 4, ... 32 seconds then retry every 32 seconds
    '''
    def __init__(self, max_retry_interval=32):
        super().__init__()
        self._max_retry_interval = max_retry_interval

    def increase_retry_interval(self):
        if self._retry_interval < self._max_retry_interval:
            self._retry_interval *= self._factor

    def retry(self):
        # retry forever
        return True

if __name__ == '__main__':
    runner = ApplicationRunner(
            os.environ.get("AUTOBAHN_DEMO_ROUTER", u"ws://whatever.com/ws"),
            u"realm1",
            retry_strategy=ISIBackoffStrategy(),
            debug_app=True,
        )
    runner.run(Component)

I am still learning asyncio. Thanks for you help.

webCoderLOL commented 7 years ago

Error message I saw was

session closed with reason wamp.close.transport_lost [WAMP transport was lost without closing the session before]

webCoderLOL commented 7 years ago

I forgot that I closed the event loop at onDisconnect method. Everything works great. Close this issue. :)