sbtinstruments / aiomqtt

The idiomatic asyncio MQTT client, wrapped around paho-mqtt
https://sbtinstruments.github.io/aiomqtt
BSD 3-Clause "New" or "Revised" License
393 stars 71 forks source link

The connection was lost with error `[code:7]` #235

Closed YraganTron closed 11 months ago

YraganTron commented 11 months ago

Then I use client with client_id

        reconnect_interval = 5
        self._mqtt_consume_ran = True
        while self._mqtt_consume_ran:
            try:
                async with Client(hostname=settings.mqtt_host, port=settings.mqtt_port, client_id='blabla44') as client:
                    async with client.messages() as messages:
                        await client.subscribe(self._resolver.get_sub_mqtt_topics())
                        rate_limiter = Semaphore(150)
                        async for message in messages:
                            self._loop.create_task(self._handle_mqtt_msg(message=message, rate_limiter=rate_limiter))
            except MqttError as e:
                self._logger.error(e)
                await sleep(reconnect_interval)

I am getting this error every 5-10sec

Could not gracefully disconnect due to "[code:7] The connection was lost.". Forcing disconnection.
empicano commented 11 months ago

Hi Arseny, thanks for opening this issue! 😋

Can you transform this into a self-contained example so that I can try to reproduce it? One reason for paho-mqtt's error code 7 is that multiple clients are connecting with the same client ID; Do you use the same client ID anywhere else?

YraganTron commented 11 months ago

Checked again, it really works. Looks like I had a hard day at work, thanks