eclipse-paho / eclipse-paho/paho.mqtt.python
keepalive does NOT work when on_message is much frequently called(on pressure)
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 742
- Avg merge
- 12d 48m
- Merged PRs (30d)
- 1
Description
Summary:
set keepalive=8.
in on_message, sleep 2 seconds.
publish message frequently, then **RECONNECTION** occurs. that's NOT expected.
It seems that if always has message to work on, the PING(heartbeat) will NEVER be sent.
the MQTT broker server is EMQ(emqx-3.0-beta.1).
subscribe with QoS0 indicate on_message will not send any ACK, right?
code:
```python
import paho.mqtt.client as mqtt
import time
import datetime
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("hello")
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
print(datetime.datetime.now())
time.sleep(2)
client = mqtt.Client()
client.will_set("die", "die")
client.on_connect = on_connect
client.on_message = on_message
client.connect("localhost", 1883, 8)
client.loop_forever()
```
and run it.
open another terminal, type:
```bash
mosquitto_pub -t 'hello' -m '111' -r
# run them quickly
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
mosquitto_pub -t 'hello' -m '222'
...
```
the python console output:
```bash
$python3 main.py
Connected with result code 0
hello b'111'
2018-09-04 13:36:07.738074
hello b'222'
2018-09-04 13:36:13.008156
hello b'222'
2018-09-04 13:36:15.011262
hello b'222'
2018-09-04 13:36:17.014952
hello b'222'
2018-09-04 13:36:19.018574
hello b'222'
2018-09-04 13:36:21.021358
hello b'222'
2018-09-04 13:36:23.024580
#----> note this line, it's reconnected <-----
Connected with result code 0
hello b'111'
2018-09-04 13:36:26.031771
```
and when RECONNECTION occurs, we can see the last will `die` in the same time.
Contributor guide
Research direction
Start with the provided Python client using loop_forever(), keepalive=8, and the on_message callback that sleeps for 2 seconds. Reproduce the behavior against EMQX with repeated mosquitto_pub messages and observe whether the connection sends its heartbeat under sustained message pressure. Done means the client no longer reconnects solely because frequent callbacks delay keepalive processing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100