nanomsg / nng

nanomsg-next-generation -- light-weight brokerless messaging
https://nng.nanomsg.org
MIT License
3.78k stars 485 forks source link

mqttv5_client chokes on CONNACK packet #1832

Closed pmf closed 4 months ago

pmf commented 4 months ago

Describe the bug When connecting to a (nanomq) broker with the mqttv5_client demo program (sub subcommand), it chokes on the CONNACK packet because there's this assert in the receive path that only allows PUBLISH packets:

assert(nng_mqtt_msg_get_packet_type(msg) == NNG_MQTT_PUBLISH);

Replacing the assert by a check for PUBLISH and a branch that just frees the message in case it is not a PUBLISH message solves the issue (via printf(), I determined that the violating packet was a CONNACK packet).

Expected behavior The subscription use of mqttv5_client (see in section about reproduction below) succeeds and receives changes.

Actual Behavior The subscription use of mqttv5_client exits in the following way:

root@xxx:/data/nng# ./mqttv5_client sub mqtt-tcp://127.0.0.1:1883 0 foo
Connecting to server ...
connect_cb: connected! RC [0] 
Start receiving loop:
mqttv5_client: /home/xxx/nng/demo/mqttv5/mqttv5_client.c:460: main: Assertion 
`nng_mqtt_msg_get_packet_type(msg) == NNG_MQTT_PUBLISH' failed.
Aborted

To Reproduce Start nanomq Start a periodic publishing task: ./mqttv5_client pub mqtt-tcp://127.0.0.1:1883 0 foo "bar" 1000 1 Start a subscriber for this topic: ./mqttv5_client sub mqtt-tcp://127.0.0.1:1883 0 foo

Environment Details

Additional context n/a

JaylinYu commented 4 months ago

... This belongs to nanosdk not nNG here. MQTT support is not merged yet

pmf commented 4 months ago

OK, I'll make sure to use the NanoSDK examples/demo instead of the nng examples/demos.