Comments (7)
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.
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.
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.
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.
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.
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.
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)
- How to get the IP of a failed connection attempt
- strange reconnection HOT 2
- MQTT broker reports a disconnection/reconnection... but no aiomqtt.MqttError is raised HOT 4
- Exceptions on __aenter__ not handled. HOT 2
- Reconnect Bug HOT 1
- Cannot instantiate a client due to internal mqtt problem HOT 2
- Issues with uvicorn on Windows 10 HOT 5
- [BUG] Cannot install version 2.0.0 with paho-mqtt 2.0.0 HOT 2
- [BUG] 127.0.0.1/localhost Work Incorrectly HOT 3
- Do not send messages for a long time mqtt automatically disconnects HOT 2
- Can't read incoming messages in pytests HOT 8
- No convenient way to get message without getting locked into a for loop HOT 2
- Can aiomqtt queue has a ring buffer optionοΌ for high frequense in-comming messages? HOT 1
- Is it necessary to support mqtt connection pool? HOT 1
- Operation timed out HOT 2
- DeprecationWarning: HOT 1
- Add optional dependency for PySocks to support proxy
- aiomqtt client_id HOT 2
- [Request] AnyIO compatibility HOT 1
- FastAPI Shared Client Connection HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiomqtt.