eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

Topic Alias incorrect on new connection #527

Closed dennynguyen closed 6 years ago

dennynguyen commented 6 years ago

Please fill out the form below before submitting, thank you!

If this is a bug regarding the Android Service, please raise the bug here instead: https://github.com/eclipse/paho.mqtt.android/issues/new

Topic alias still doesn't seem to be working right.

Paho client connects, publishes message to topic Messagesight trace:

2018-04-26T17:15:38.663Z tcpiop.1 mqtt.c:915: MQTT receive 32 PUBLISH connect=15: len=45
00000: 00062f53 4d5f3033 00010323 00015445 58543a20 7075626c 6f6f7020 4d657373  [../SM_03...#..TEXT: publoop Mess]
00032: 61676520 6e756d62 65723a20 31                                            [age number: 1]

Subsequent messages have topic alias

2018-04-26T17:15:38.674Z tcpiop.1 mqtt.c:915: MQTT receive 32 PUBLISH connect=15: len=39
00000: 00000002 03230001 54455854 3a207075 626c6f6f 70204d65 73736167 65206e75  [.....#..TEXT: publoop Message nu]
00032: 6d626572 3a2032                                                          [mber: 2]

We restart the server, which disconnects the clients. When the clients reconnect (new connection), the topic alias is not working correctly

2018-04-26T17:15:59.181Z tcpiop.1 mqtt.c:915: MQTT receive 32 PUBLISH connect=3: len=37
00000: 000002e3 03230001 5075624c 6f6f7032 5075626c 6973684d 65737361 67657332  [.....#..PubLoop2PublishMessages2]
00032: 3a203733 39                                                              [: 739]
2018-04-26T17:15:59.181Z tcpiop.1 mqtt.c:2366: Set error "The topic is not valid: " (276)
jpwsutton commented 6 years ago

Thanks for raising this @dennynguyen, When I fixed the issue with persisting messages with Topic aliases, I forgot to add the same check / strip to the DisconnectedMessageBuffer as well. I've now done this and added tests to validate.

leetosc commented 6 years ago

I'm still getting the same problem after the fix.

More details on the test case:

jpwsutton commented 6 years ago

Ok, I've written a new test case to cover this scenario and found the source of this problem, the topic alias queue wasn't being cleared on closure of the TCP connection. The build with this fix is available here: https://repo.eclipse.org/content/repositories/paho-snapshots/org/eclipse/paho/org.eclipse.paho.mqttv5.client/1.2.1-SNAPSHOT/org.eclipse.paho.mqttv5.client-1.2.1-20180502.102547-23.jar

dennynguyen commented 6 years ago

works now