Giter Site home page Giter Site logo

Comments (7)

4s1 avatar 4s1 commented on August 15, 2024 1

Okay, i went through client.py history.
A slightly different issue (with same symptoms) was indeed fixed in #244, but this issue was introduced thereafter by b989089

from aiomqtt.

4s1 avatar 4s1 commented on August 15, 2024

Intetersting, here I am using Python 3.11.6 on archlinux. Using the given code snipped (with a customized broker and enhanced error log) gives me

 Connection lost, [code:5] The connection was refused.; Reconnecting in 5 seconds ...
 Connection lost, The client context manager is reusable, but not reentrant; Reconnecting in 5 seconds ...
import asyncio
import aiomqtt


async def main():
    client = aiomqtt.Client("broker1.internal")
    interval = 5  # Seconds
    while True:
        try:
            async with client:
                await client.subscribe("humidity/#")
                async for message in client.messages:
                    print(message.payload)
        except aiomqtt.MqttError as e:
            print(f"Connection lost, {e}; Reconnecting in {interval} seconds ...")
            await asyncio.sleep(interval)


asyncio.run(main())

from aiomqtt.

tsturzl avatar tsturzl commented on August 15, 2024

I believe this issue was fixed as of the 1.2.1 release: https://github.com/sbtinstruments/aiomqtt/releases/tag/v1.2.1

There was another ticket that was fixed and closed mentioned in the release notes. I believe that fixes the issue. I'd recommend making sure you're running that version. I was having a similar issue, and upgrading to 1.2.1 fixed it. I assume the 2.0.0 release also addresses the issue.

from aiomqtt.

4s1 avatar 4s1 commented on August 15, 2024

Well. I have 2.0.0 installed here and used the example script to connect to a broker, which my firewall prohibits (icmp port closed reply) to emulate a connection issue (without the delay part).

So you can test yourself, this isn't fixed with 2.0.0.

That's why i've created a merge request for current master

from aiomqtt.

tsturzl avatar tsturzl commented on August 15, 2024

I could be wrong. I'm not running 2.0.0 yet, but I know that moving to 1.2.1 had fixed this issue for me. Hopefully this is resolved in 2.0.0, it's good to know it's still an issue there, so I can make sure we await the fix in that version before upgrading. I'm not a contributor, I just saw this while looking for another bug and recently stumbled upon a similar issue.

I'm also realizing I may be wrong, I think the fix originally landed in 1.2.0. The original issue is #244 which was fixed by PR #245. I'm not sure if it's the same issue, but it seems very similar.

from aiomqtt.

tsoos99dev avatar tsoos99dev commented on August 15, 2024

I've tried with both aiomqtt 2.0.0 and 1.2.1 and ([code:5] The connection was refused) error renders the client unusable by leaving the internal lock in the locked state. It'd be nice if the client was reusable.

async def run(self):
    while True:
        try:
            async with self.client as client:
                await self._process_messages(client)
        except aiomqtt.MqttError as e:
            logger.warning(f"Connection lost ({e}). Reconnecting in {self.reconnect_interval} seconds ...")
            await asyncio.sleep(5.0)

from aiomqtt.

empicano avatar empicano commented on August 15, 2024

Hi all, thanks for the great discussion! 😎 With 2.0.1, both (1.) a negative CONNACK response and (2.) a timeout while waiting on the CONNACK response should now be correctly handled.

(Note that there's currently another issue related to reconnection that's still open. The workaround is to use client._messages() instead of client.messages.)

Please reopen if there's anything that's still not working, or otherwise left unclear πŸ™‚

from aiomqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.