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

Mosquitto_pub reuses topic alias after reconnect, which is not allowed #2494

Closed
halfgaar opened this issue Mar 27, 2022 · 1 comment
Closed
Labels
Component: mosquitto-clients Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Milestone

Comments

@halfgaar
Copy link

Mosquitto_pub reuses topic alias after reconnect, which is not allowed.

To reproduce, do:

( while true; do echo "$(date)" ; sleep 1; done ) | ./mosquitto_pub -D publish topic-alias 1 -l -d -t a/b/c/d

Here's a session, in which one/two/three/four/five is specified once, then reused:

$ ( while true; do echo "$(date)" ; sleep 1; done ) | ./mosquitto_pub -D publish topic-alias 1 -l -d -t one/two/three/four/five
Client (null) sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m1, 'one/two/three/four/five', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m2, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m3, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m4, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m5, '(null)', ... (29 bytes))

-- Stop server
-- Start server

-- It will handshake again:
Client RgI04TXDn6no7UyHMmXlvnR sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)

-- And reuse the topic alias. The server rejects the client, because the topic is empty all the time
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m10, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m11, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m12, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m13, '(null)', ... (29 bytes))
Client RgI04TXDn6no7UyHMmXlvnR sending CONNECT
Client RgI04TXDn6no7UyHMmXlvnR received CONNACK (0)
Client RgI04TXDn6no7UyHMmXlvnR sending PUBLISH (d0, q0, r0, m14, '(null)', ... (29 bytes))

The MQTT 5.0 specs say:

Topic Alias mappings exist only within a Network Connection and last only for the lifetime of that Network Connection. A receiver MUST NOT carry forward any Topic Alias mappings from one Network Connection to another.

./mosquitto_pub --version
mosquitto_pub version 2.0.12 running on libmosquitto 2.0.12.

BTW: why is everything 29 bytes? Is that correct?

@Daedaluz
Copy link
Contributor

Peeking in the source, I find that there is a first_publish variable that is never reset.
Perhaps simply resetting it in the connect callback will fix it.

BTW: why is everything 29 bytes? Is that correct?

Mine publishes 32 bytes. I wouldn't expect $(date) to vary in length much.

ralight added a commit that referenced this issue Apr 29, 2022
Fix mosquitto_pub incorrectly reusing topic aliases when reconnecting.

Closes #2494.
@ralight ralight added this to the 2.0.15 milestone Aug 10, 2022
@ralight ralight added Type: Bug Component: mosquitto-clients Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. labels Aug 10, 2022
@ralight ralight closed this as completed Aug 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Component: mosquitto-clients Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. Type: Bug
Projects
None yet
Development

No branches or pull requests

3 participants