peterhinch / micropython-mqtt

A 'resilient' asynchronous MQTT driver. Recovers from WiFi and broker outages.
MIT License
550 stars 117 forks source link

mqtt_as.py not recovering when starting while broker on host is down. #44

Closed chrisovergaauw closed 4 years ago

chrisovergaauw commented 4 years ago

Hi Peter,

When I start with terminating my mosquitto broker and then start initialising the mqtt client an exception is raised:

Traceback (most recent call last): File "uasyncio/core.py", line 1, in run_until_complete File "mqtt_as.py", line 519, in connect File "mqtt_as.py", line 248, in _connect File "mqtt_as.py", line 188, in _as_write OSError: [Errno 104] ECONNRESET

This seems to bubble up to the task itself, so it does not automatically recover. Would you consider this a bug and is it worth fixing here?

I can imagine this to be a scenario where you've explicitly chosen not to recover, but for my scenario it's something I should expect and I'll have to find a fix to recover from this.

regards, Chris

peterhinch commented 4 years ago

I can imagine this to be a scenario where you've explicitly chosen not to recover

This is the case. The assumption in the design is that network and broker are available on startup.

Note, in coding a solution, that socket.getaddrinfo blocks, potentially for a long time. The module calls this once on startup to ensure that blocking does not occur on reconnect.