wialon / gmqtt

Python MQTT v5.0 async client
MIT License
400 stars 52 forks source link

Develop my own fault recovery logic using gmqtt client #121

Open emoriones opened 3 years ago

emoriones commented 3 years ago

Hello,

I am trying to implement my own fault handling logic using gmqtt client. To do so, I set reconnect_retries in client config to 0. However, when I am using the client normally an I force a broker error I see the errors are still managed by the client like it can be see in the following logs:

error ERROR HANDLE PKG
warning TRYING WRITE TO CLOSED SOCKET
warning CAN'T RECONNECT 1
error DISCONNECTED max number of failed connection attempts achieved

I noticed the exception I want to propagate to handle the error is always swallowed by the following method in the gmqtt.mqtt.handler module.

def __call__(self, cmd, packet):
        try:
            result = self._handle_packet(cmd, packet)
        except Exception as exc:
            logger.error('[ERROR HANDLE PKG]', exc_info=exc)
            result = None
        return result

Is there a way to avoid this and propagate the exception?