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

Message queuing using --disable-clean-session option not working in mosquitto_sub #2134

Closed
fuxoft opened this issue Mar 13, 2021 · 2 comments
Milestone

Comments

@fuxoft
Copy link

fuxoft commented Mar 13, 2021

I have created this minimal Linux script to show the problem:

I am attempting to queue 10 messages and then receive them separately, one after another, using command line tools. The first message is received and displayed but the remaining 9 are never displayed.

(Mosquitto server runs with default configuration)

#!/usr/bin/bash
# Clear sessin for client "receiver" (ends with timeout as expected):
mosquitto_sub -V 5 -i receiver --nodelay -q 2 -W 1 -t "spam"
# Tell the server to store "receiver"'s session (ends with timeout as expected):
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -W 1 -t "spam"
# Queuing 10 messages:
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "A"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "B"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "C"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "D"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "E"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "F"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "G"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "H"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "I"
mosquitto_pub -V 5 -i spammer --nodelay -q 2 -t "spam" -m "J"
# Expecting to receive 10 messages one after another
# but receiving only first message ("A") plus 9 timeouts:
echo "Attempting to receive A"
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -d -C 1 -W 1 -t "spam" -v
echo "Attempting to receive B"
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -d -C 1 -W 1 -t "spam" -v
echo "Attempting to receive C"
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -d -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v
mosquitto_sub -V 5 -c -i receiver --nodelay -q 2 -C 1 -W 1 -t "spam" -v

Complete script output follows. Look especially at the debug output after "Attempting to receive B". 9 messages seem to be received all at once and never printed:

Timed out
Timed out
Attempting to receive A
Client receiver sending CONNECT
Client receiver received CONNACK (0)
Client receiver sending SUBSCRIBE (Mid: 1, Topic: spam, QoS: 2, Options: 0x00)
Client receiver received PUBLISH (d0, q2, r0, m1, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m1, rc0)
Client receiver received PUBLISH (d0, q2, r0, m2, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m2, rc0)
Client receiver received PUBLISH (d0, q2, r0, m3, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m3, rc0)
Client receiver received PUBLISH (d0, q2, r0, m4, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m4, rc0)
Client receiver received PUBLISH (d0, q2, r0, m5, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m5, rc0)
Client receiver received PUBLISH (d0, q2, r0, m6, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m6, rc0)
Client receiver received PUBLISH (d0, q2, r0, m7, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m7, rc0)
Client receiver received PUBLISH (d0, q2, r0, m8, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m8, rc0)
Client receiver received PUBLISH (d0, q2, r0, m9, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m9, rc0)
Client receiver received PUBLISH (d0, q2, r0, m10, 'spam', ... (1 bytes))
Client receiver sending PUBREC (m10, rc0)
Client receiver received SUBACK
Subscribed (mid: 1): 2
Client receiver received PUBREL (Mid: 1)
Client receiver sending PUBCOMP (m1)
spam A
Client receiver sending DISCONNECT
Attempting to receive B
Client receiver sending CONNECT
Client receiver received CONNACK (0)
Client receiver sending SUBSCRIBE (Mid: 1, Topic: spam, QoS: 2, Options: 0x00)
Client receiver received PUBREL (Mid: 2)
Client receiver sending PUBCOMP (m2)
Client receiver received PUBREL (Mid: 3)
Client receiver sending PUBCOMP (m3)
Client receiver received PUBREL (Mid: 4)
Client receiver sending PUBCOMP (m4)
Client receiver received PUBREL (Mid: 5)
Client receiver sending PUBCOMP (m5)
Client receiver received PUBREL (Mid: 6)
Client receiver sending PUBCOMP (m6)
Client receiver received PUBREL (Mid: 7)
Client receiver sending PUBCOMP (m7)
Client receiver received PUBREL (Mid: 8)
Client receiver sending PUBCOMP (m8)
Client receiver received PUBREL (Mid: 9)
Client receiver sending PUBCOMP (m9)
Client receiver received PUBREL (Mid: 10)
Client receiver sending PUBCOMP (m10)
Client receiver received SUBACK
Subscribed (mid: 1): 2
Client receiver sending DISCONNECT
Timed out
Attempting to receive C
Client receiver sending CONNECT
Client receiver received CONNACK (0)
Client receiver sending SUBSCRIBE (Mid: 1, Topic: spam, QoS: 2, Options: 0x00)
Client receiver received SUBACK
Subscribed (mid: 1): 2
Client receiver sending DISCONNECT
Timed out
Timed out
Timed out
Timed out
Timed out
Timed out
Timed out
Timed out

@ralight
Copy link
Contributor

ralight commented Mar 13, 2021

Thanks, that's a handy script. This is straightforward to fix for MQTT v5 in principle using the receive maximum property. It's less easy for MQTT v3*. I'd have a fix for you already, but it has highlighted something else I need to fix first.

@fuxoft
Copy link
Author

fuxoft commented Mar 13, 2021

Oh, so I am not doing anything wrong and it's indeed a bug? That's a relief, I was going crazy over it for 2 hours, thanks.

ralight added a commit that referenced this issue Mar 14, 2021
This is for mosquitto_sub and mosquitto_rr, to avoid potentially lost
messages.

Closes #2134. Thanks to Frantisek Fuka.
ralight added a commit that referenced this issue Mar 14, 2021
This is for when it takes over an old session.

Closes #2134. Thanks to Frantisek Fuka.
@ralight ralight added this to the 2.0.10 milestone Apr 3, 2021
@ralight ralight closed this as completed Apr 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants