moquette-io / moquette

Java MQTT lightweight broker
http://moquette-io.github.io/moquette/
Apache License 2.0
2.27k stars 814 forks source link

Broker restart and clear connections,but aslo can response client PINGEQ message #731

Open kscorpio opened 1 year ago

kscorpio commented 1 year ago

Broker restart (less than 5 s ) and clear connections,but aslo can response client PINGEQ message,but getConnectedList is empty ,

the client set ping interval = 20s,

andsel commented 1 year ago

Hi @kscorpio , please could you expand more on your problem? Do you want that the broker respond to the PING while restarting?

kscorpio commented 1 year ago

moquette stopped and after 5 seconds restart, the client send ping ,the moquette can also response , but broker.listConnectedClients() is empty .

kscorpio commented 1 year ago

when i restart broker , and call api getConnectionList , return empty but in the debug log ,has many line like below C->B PINGREQ < null > if the client is connected , the ping log should be C->B PINGREQ <'clientID'> @andsel

kscorpio commented 1 year ago

MQTTConnection.class line 105

 case PINGREQ:
                String cid = NettyUtils.clientID(channel);
                if (!StringUtil.isNullOrEmpty(cid)) {
                    MqttFixedHeader pingHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, AT_MOST_ONCE,
                        false, 0);
                    MqttMessage pingResp = new MqttMessage(pingHeader);
                    channel.writeAndFlush(pingResp).addListener(CLOSE_ON_FAILURE);
                }

maybe can resovle the problem ?

andsel commented 1 year ago

Thank's @kscorpio for all this tests and investigations, I'll try to wrap up next weekend. Just for confirmation, does this happen on main branch?

kscorpio commented 1 year ago

yes , 0.17-snopshot

can is use maven package get a temp jar to use. ?

andsel commented 1 year ago

Hi @kscorpio I tried to reproduce the issue without any success. I improved the EmbeddedLauncher to exit or list_clients, please checkout PR #746 and start with:

./mvnw clean package exec:java -pl embedding_moquette

Using the HiveMQ CLI tool on broker restart, the client reconnects and the ping messages has all the clientid.

Press Ctl-C to exit.

Using default values from properties file /home/andrea/.mqtt-cli/config.properties:
Host: localhost, Port: 1883, Mqtt-Version MQTT_5_0, Logfile-Debug-Level: DEBUG
No Logfile used - Activate logging with the 'mqtt sh -l' option
mqtt> con -V 3 -h 127.0.0.1 -i andsel_pub -k 10
andsel_pub@127.0.0.1> pub -t /temperature/milan -m 18
andsel_pub@127.0.0.1> pub -t /command -m list_clients
andsel_pub@127.0.0.1> Server closed connection without DISCONNECT.
Press ENTER to resume: 
mqtt> con -V 3 -h 127.0.0.1 -i andsel_pub -k 10

Do you have a reproducer, or could you use the EmbeddedLauncher to verify your client? Maybe it depends on the way the embedded broker instance is managed, could describe more or provide a local reproducer, please?