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

fix: PUBACK packet not compatible with RabbitMQ #142

Merged
merged 4 commits into from
Jul 7, 2023

Conversation

alaendle
Copy link
Contributor

@alaendle alaendle commented Jul 4, 2023

MQTT5 spec is not so clear about the possible remaining length of PUBACK pakets.

We have:

  • If there are no properties, this MUST be indicated by including a Property Length of zero [MQTT-2.2.2-1].
    This clearly allows us to have packets like [64, 4, 0 42, 0, 0] (puback, length:4, pakedId: 0 42, reason: 0, properties: 0]
  • The Client or Server sending the PUBACK packet MUST use one of the PUBACK Reason Codes [MQTT-3.4.2-1]. The Reason Code and Property Length can be omitted if the Reason Code is 0x00 (Success) and there are no Properties. In this case the PUBACK has a Remaining Length of 2.
    This allows packets like [64, 2, 0, 42]
  • The discussion starts if it is valid to only have the reason byte without the properties length (due to the unclear statement in
    3.4.2.2.1 Property Length The length of the Properties in the PUBACK packet Variable Header encoded as a Variable Byte Integer. If the Remaining Length is less than 4 there is no Property Length and the value of 0 is used. )
    So basically - ist it valid to have [64, 3, 0, 42, 0]? I would argue no, the remaining length should be 2 or >= 4. So this patch strives to only generate packets with this remaining length. However we are still able to parse packets with a remaining length of 3.

To state my belief - if it were intended to be able to omit both bytes individually, it wouldn't makle sense limit this to reason code 0x00 - why should [64, 3, 0, 42, 0] be allowed, while [64, 3, 0, 42, 135] is not?

Fixes #92

@robertsLando
Copy link
Member

@alaendle remember to add a test suite that covers the issue

@alaendle
Copy link
Contributor Author

alaendle commented Jul 4, 2023

Please note that this is a breaking change on the wire - however it shouldn't be with regards to the specification. It could be further optimized by striving for length === 2 (but this would also need an additional complexity by checking the reason code). So I basically adapted the existing test code - because I fear there is no backwards compatible way to implement this. Tested against the "old" version of RabbitMQ that treated length === 3 as a protocol error.

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add mqtt specs links to specific section in the comments.

Also could you explain me how this could be a breaking change? Let's say I have a broker using mqtt-packet with this patch version and an mqtt client (using mqttjs that uses this library too) with an older mqtt-packet implementation. The broker sends the puback packet, it is encoded following this new standard, will mqttjs client be able to decode it with the older version?

If nope does this only happens when using mqtt5 protocol?

writeToStream.js Outdated Show resolved Hide resolved
writeToStream.js Show resolved Hide resolved
Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also add mqtt specs links to specific section in the comments.

Also could you explain me how this could be a breaking change? Let's say I have a broker using mqtt-packet with this patch version and an mqtt client (using mqttjs that uses this library too) with an older mqtt-packet implementation (consider also the opposite case). The broker sends the puback packet, it is encoded following this new standard, will mqttjs client be able to decode it with the older version?

If nope does this only happens when using mqtt5 protocol?

@alaendle
Copy link
Contributor Author

alaendle commented Jul 5, 2023

Please note I have added a description of the PR just now - #142 (comment) - to make sure we discuss the same things 😄

test.js Show resolved Hide resolved
@robertsLando robertsLando changed the title Hack to solve #92. fix: PUBACK packet not compatible with RabbitMQ Jul 5, 2023
@robertsLando
Copy link
Member

robertsLando commented Jul 5, 2023

@mcollina Thoughts on this? It looks good to me, if you agree could you merge and release a patch?

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit bb3af28 into mqttjs:master Jul 7, 2023
3 checks passed
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

Successfully merging this pull request may close these issues.

Mqtt 5 puback is different from spec
3 participants