Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceeded reconnect_retries seems seems not to be working #130

Open
presedo93 opened this issue Jul 16, 2021 · 1 comment
Open

Exceeded reconnect_retries seems seems not to be working #130

presedo93 opened this issue Jul 16, 2021 · 1 comment

Comments

@presedo93
Copy link

I was looking for a way of checking if the reconnect_tries was exceeded and found this issue: #72 that was asking the same. It has a PR associated: #76

The thing is I've tried the solution proposed with gmqtt==0.6.9 and on_disconnect is only called when the first disconnection happens...

def on_disconnect(self, client: gmqtt.Client, packet: bytes, exc: None = None):
    if client.failed_connections > client.reconnect_retries:
    #    method that logs that the system couldn't reconnect...

Thanks!

@presedo93 presedo93 changed the title Exceeded reconnect_retries seems not to be working Exceeded reconnect_retries seems seems not to be working Jul 16, 2021
@nicoCalvo
Copy link

If it helps, I solved with a small workaround:

 def  close_con(client):
        if client.is_connected:
            return
        loop = asyncio.get_running_loop()
        logger.info('STOPPING EVENT LOOP')
        loop.stop()
        pending = asyncio.Task.all_tasks()

        # Run loop until tasks done:
        logger.info('CANCELING REMAINING TASKS')
        loop.run_until_complete(asyncio.gather(*pending))

        logger.info("Shutdown complete ...")  

def _on_disconnect(self, client, packet):
        loop = asyncio.get_running_loop()
        # only call if max reconnect retries is defined
        if client.reconnect_retries > 0:
            grace_time = (client.reconnect_retries * client.reconnect_delay) + 1
            loop.call_later(grace_time, close_con, client)

If the reconnect happens during the scheduled shutdown function, the tasks are not cancelled.
If another disconnect event occurs after having reconnected, the funcion is re-scheduled.
Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants