Skip to content

Commit 163c730

Browse files
committed
PUBLISH can arrive before SUBACK
fixes #192
1 parent 7aacbfe commit 163c730

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,15 @@ def subscribe(self, topic: str, qos: int = 0) -> None:
880880
if self.on_subscribe is not None:
881881
self.on_subscribe(self, self.user_data, t, q)
882882
self._subscribed_topics.append(t)
883+
883884
return
884885

885-
raise MMQTTException(
886-
f"invalid message received as response to SUBSCRIBE: {hex(op)}"
887-
)
886+
if op != MQTT_PUBLISH:
887+
# [3.8.4] The Server is permitted to start sending PUBLISH packets
888+
# matching the Subscription before the Server sends the SUBACK Packet.
889+
raise MMQTTException(
890+
f"invalid message received as response to SUBSCRIBE: {hex(op)}"
891+
)
888892

889893
def unsubscribe(self, topic: str) -> None:
890894
"""Unsubscribes from a MQTT topic.

0 commit comments

Comments
 (0)