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

Paho MQTT Client Fails to Reconnect After Prolonged Network Downtime #785

Open
surfskidude opened this issue Dec 27, 2023 · 2 comments
Open
Labels
Status: Available No one has claimed responsibility for resolving this issue. Status: More info needed More information needed from issue author

Comments

@surfskidude
Copy link

The Paho MQTT client fails to automatically reconnect after the network has been down for a prolonged period. While client.loop_start() should handle reconnections, it isn't effective in cases of long-term network disconnections.

Changing client.loop_start() to client.loop_forever(retry_first_connection=True) resolves the issue, suggesting that the client's default reconnection mechanism might not handle prolonged network outages effectively.

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Dec 27, 2023
@MattBrittan
Copy link
Contributor

loop_start effectively just calls loop_forever(retry_first_connection=True) in a thread. Are you able to provide any additional information? (what is a "prolonged period", is anything logged etc).

@MattBrittan MattBrittan added the Status: More info needed More information needed from issue author label Dec 29, 2023
@surfskidude
Copy link
Author

When I changed the code from the commented out to the current, things started working, and it reconnected on prolonged periods:

client.connect(MQTT_BROKER, MQTT_PORT, 60)
#client.loop_start()
client.loop_forever(retry_first_connection=True)

#try:
#    while True:
#        time.sleep(1)  # Keep the main thread alive.
#except KeyboardInterrupt:
#    print("Exiting...")
#finally:
#    client.loop_stop()
#    client.disconnect()

I am running this on a Raspberry Pi and have an issue with the network. Here is the log from dmesg:

[Wed Dec 27 08:56:15 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Wed Dec 27 08:56:19 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Wed Dec 27 08:56:30 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Wed Dec 27 08:56:33 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Wed Dec 27 10:27:22 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Wed Dec 27 21:06:33 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Wed Dec 27 21:56:51 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Thu Dec 28 06:51:45 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Thu Dec 28 12:28:42 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Thu Dec 28 13:19:19 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Thu Dec 28 16:37:49 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Thu Dec 28 16:59:21 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx
[Thu Dec 28 21:51:38 2023] bcmgenet fd580000.ethernet eth0: Link is Down
[Fri Dec 29 06:30:03 2023] bcmgenet fd580000.ethernet eth0: Link is Up - 1Gbps/Full - flow control rx/tx

As you can see from the above log, the network is down for up to 9 hours.

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. Status: More info needed More information needed from issue author
Projects
None yet
Development

No branches or pull requests

2 participants