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

broker rejects connect with empty will message #154

Open
dirkfeytons opened this issue Mar 22, 2024 · 0 comments
Open

broker rejects connect with empty will message #154

dirkfeytons opened this issue Mar 22, 2024 · 0 comments

Comments

@dirkfeytons
Copy link

A client that has the will flag set, a will topic specified but an empty will message is rejected by the broker with the error message "will flag set, but will topic/message not present in payload".
It seems the code is confusing an empty will message (i.e. field present but with the length set to 0, which is valid) with the absence of the field (which is not according to the spec).

A change like below seems to fix it but I'm not 100% sure this is indeed the right fix:

diff --git a/amqtt/codecs.py b/amqtt/codecs.py
index 45cb7c5..1057fa6 100644
--- a/amqtt/codecs.py
+++ b/amqtt/codecs.py
@@ -83,7 +83,10 @@ async def decode_data_with_length(reader) -> bytes:
     """
     length_bytes = await read_or_raise(reader, 2)
     bytes_length = unpack("!H", length_bytes)
-    data = await read_or_raise(reader, bytes_length[0])
+    if bytes_length[0]:
+        data = await read_or_raise(reader, bytes_length[0])
+    else:
+        data = b""
     return data
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

1 participant