empicano / aiomqtt

The idiomatic asyncio MQTT client
https://aiomqtt.bo3hm.com
BSD 3-Clause "New" or "Revised" License
427 stars 75 forks source link

strange reconnection #282

Closed victorrova closed 8 months ago

victorrova commented 8 months ago

Hello guys, let's see if you can help me with this: I have several different clients running on the same code, everything works fine until I try to reconnect.

this is the function:

async def msg_pool(self):
        timer1 = time.time()
        self.log.info("[%s] msg_pool iniciado",self.id)
        while True:
            try:
                async with self.client:
                    self.connect = True
                    await self.client.subscribe(self.topic)
                    async for msg in self.client.messages:
                        await self.queue.put(msg.payload)
                        self.log.debug("mensaje entrante desde %s",msg.topic)
                        self.num_msg += 1
            except aiomqtt.MqttError:
                self.num_msg = 0
                self._reconn += 1
                self.log.error("conexión perdida,intentando reconectar")
                await asyncio.sleep(3)

            timer2 = time.time() - timer1
            if timer2 > 60:
                self.msg_x_min = self.num_msg / timer2
                timer1 = time.time()

            await asyncio.sleep(self.time_interval)

there is no type of error and the output log is this:

2024-03-02T18:54:27 asyncio_1 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'coreprueba' 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m62) [(b'prueba/core', 0)] 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:27 asyncio_0 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'pc' 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m59) [(b'prueba/pc', 0)] 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:27 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:28 asyncio_1 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'coreprueba' 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m63) [(b'prueba/core', 0)] 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:28 asyncio_0 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'pc' 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m60) [(b'prueba/pc', 0)] 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:28 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:29 asyncio_1 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'coreprueba' 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m64) [(b'prueba/core', 0)] 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:29 asyncio_0 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'pc' 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m61) [(b'prueba/pc', 0)] 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:29 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:30 asyncio_1 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'coreprueba' 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m65) [(b'prueba/core', 0)] 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:30 asyncio_0 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'pc' 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m62) [(b'prueba/pc', 0)] 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:30 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:31 asyncio_1 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'coreprueba' 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m66) [(b'prueba/core', 0)] 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT 2024-03-02T18:54:31 asyncio_0 DEBUG client _easy_log :2529 Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b'pc' 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Received CONNACK (0, 0) 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Sending SUBSCRIBE (d0, m63) [(b'prueba/pc', 0)] 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Received SUBACK 2024-03-02T18:54:31 MainThread DEBUG client _easy_log :2529 Sending DISCONNECT

never for.... where am i wrong?

empicano commented 8 months ago

Hi there! 😊 This looks like a duplicate of #268. Could you try to replace client.messages with client._messages()?

victorrova commented 8 months ago

Thanks for the help! FrankensteinItsAliveGIF