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

MQTT Client reconnection bug #383

Closed
SuperDPX opened this issue May 16, 2023 · 4 comments
Closed

MQTT Client reconnection bug #383

SuperDPX opened this issue May 16, 2023 · 4 comments

Comments

@SuperDPX
Copy link

When my MQTT client connects to the server for a certain period of time, [onClose] and [onConnect] will be continuously and infinitely called.

@ithewei
Copy link
Owner

ithewei commented May 16, 2023

show your reconn_setting and log

@SuperDPX
Copy link
Author

SuperDPX commented May 18, 2023

When I start the service and disconnect the network for a period of time, then restore the connection, it keeps triggering the [onClose] and [onConnect] callback repeatedly. The following logs are outputted in the libhv.log file:

2023-05-18 09:49:25.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:49:25.861 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:49:50.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:49:50.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:50:01.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:50:01.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:50:12.860 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]
2023-05-18 09:50:12.861 ERROR mqtt no pong! [mqtt_client.c:51:mqtt_send_ping]

Here is my reconn_setting

p_mqtt = new hv::MqttClient();
reconn_setting_t reconn;
reconn_setting_init(&reconn);
reconn.min_delay = 1000;
reconn.max_delay = 10000;
reconn.delay_policy = 2;
p_mqtt->setReconnect(&reconn);
p_mqtt->setPingInterval(10);

@ithewei
Copy link
Owner

ithewei commented May 22, 2023

Log is very clear, your mqtt server not response pong, you can try setPingInterval(0) to control not to send ping.

@SuperDPX
Copy link
Author

I did a packet capture test with wireshark.

When I start the program, the program can send ping normally, and the server can also send pong normally. Then when I disconnect from the network for a period of time, the program’s reconnection mechanism will be triggered. At this time, the program will no longer actively send ping, so it cannot jump out of the reconnection loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants