Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on_connect not called after reconnection after server restart #871

Open
Zugschlus opened this issue Nov 16, 2024 · 2 comments
Open

on_connect not called after reconnection after server restart #871

Zugschlus opened this issue Nov 16, 2024 · 2 comments
Labels
Status: Available No one has claimed responsibility for resolving this issue.

Comments

@Zugschlus
Copy link

Zugschlus commented Nov 16, 2024

Hi,

I have an simple program that connects to a server (which is mosquitto running in docker). I have added some error handling so that the client doesn't abort when the server dies or restarts. My program subscribes to a topic in the on_connect method. When the server restarts, the client reconnects to the server, but on_connect is not called.

Reproduction

Start the attached program with --console-loglevel=debug. Let it sit for a few seconds:

# pvenv/bin/python3 mqttkeks --console-loglevel=debug
create mqtt.Client
mqtt.Client created
mqtt.start(
(Re)connected successfully to MQTT
restarted MQTT loop
)
Connected to MQTT broker rc=ReasonCode(Connack, 'Success')
Subscribed to self.subscribe_topic='tele/rain/raw_json'

then restart the server (on my machine: docker compose restart), keeping the reproducer running

Disconnected from MQTT broker with result code Unspecified error
Attempting to reconnect to MQTT broker...
Failed to connect to MQTT broker: (Attempt 1): [Errno 111] Connection refused
Retrying connection in 5 seconds...
(Re)connected successfully to MQTT
restarted MQTT loop

notice that the "Connected to MQTT broker" and the "Subscribed to self.subscribe_topic" is not present.

I don't claim that I am doing things right. But the docs are silent on error handling.

Sorry that my example needs your own MQTT broker, but you can't restart a public broker on request.

Environment

  • Python version: 3.12.7
  • Library version: 2.1.0
  • Operating system (including version): Debian GNU/Linux unstable (in a container). Reproducible on both plain Debian GNU/linux unstable (with paho-mqtt 2.0.0) and on Debian GNU/Linux stable (with paho-mqtt 1.6)
  • MQTT server (name, version, configuration, hosting details): Mosquitto 2.0.8 in docker, compose file and mosquitto.conf attached.

Thanks for your consideration, and for providing paho-mqtt in the first place.

Greetings, Marc

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Nov 16, 2024
@Zugschlus
Copy link
Author

Zugschlus commented Nov 16, 2024

paho-mqtt-871.zip

$ unzip -v paho-mqtt-871.zip Archive:  paho-mqtt-871.zip
Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
4484  Defl:N     1282  71% 2024-11-16 07:51 607070ad  paho-mqtt-871-reproducer
195  Defl:N      131  33% 2024-11-16 07:51 5b400824  mosquitto.conf
448  Defl:N      239  47% 2024-11-16 07:51 b0b08d1f  docker-compose.yml
--------          -------  ---                            -------
5127             1652  68%                            3 files

Sorry, github didn't allow me to upload those files directly ("unsupported file type")

@JamesParrott
Copy link

Please post the Python code enclosed in triple back ticks.

How're we supposed to know we're not downloading malware in paho-mqtt-871-reproducer ?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

2 participants