eclipse-mosquitto / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
9.07k stars 2.39k forks source link

half open broker socket is replaying stale msgs after reconnection #1760

Open gawaskar21 opened 4 years ago

gawaskar21 commented 4 years ago

Hi Guys, I am facing an issue and dont know if it is expected behaviour of mosquitto or it is a bug. May be i have missed some flag.

I have a subscriber and a publisher connected to broker. I am seeing following behaviour when i make the subscriber client link down and up.

keep alive time: 10 mins

  1. subscriber to broker link goes down
  2. publisher is still publishing msgs.
  3. subscriber link comes up after 5 mins and it does a send__connect.
  4. broker doesn't do CONNACK to subscriber yet.. it waits for keep alive timer to expire which is 10x1.5=15mins.
  5. After 15 mins, broker sends LWT message to publisher and immediately does CONNACK 0 to subscriber.
  6. subscriber subscribes to topic and it starte receiving old messages which were published by publisher at step 2.

subscriber and broker connection reconnects with cleanSession flag true and msgs on topic are with retain flag false, qos = 0.

Is this behaviour expected ? My requirement is to get latest msg after subscriber reconnects. Also When subscriber reconnects, is there any way to connect it with broker immediately rather than waiting for keep alive timer to expire.

Any help is appreciated.

Thanks....

ralight commented 4 years ago

What version of Mosquitto are you using, and on what platform?

Also, are you using websockets? If so, then what version of libwebsockets?

ralight commented 4 years ago

I've tried to reproduce this with and without websockets and am getting exactly the expected results. Are you able to produce a detailed step by step guide to reproducing this with all of the details so I can find what I am doing different?

gawaskar21 commented 4 years ago

I am using mosquitto version 1.5.5 , Linux x86_64 OS. Not using websockets.

This behaviour is not seen every time. I see it once every 5 or 6 publisher link flap. Trigger is publisher link flap with lots of continuous msg going on from publisher. Is there any way to clear data in half open socket ?