hivemq / hivemq-community-edition

HiveMQ CE is a Java-based open source MQTT broker that fully supports MQTT 3.x and MQTT 5. It is the foundation of the HiveMQ Enterprise Connectivity and Messaging Platform
https://www.hivemq.com
Apache License 2.0
1.06k stars 266 forks source link

Retained publish not fully processed when connection closes ungracefully #341

Open xadh00m opened 2 years ago

xadh00m commented 2 years ago

Expected behavior

If a client publish message (retained, QoS 0,1,2) reaches the broker it should be forwarded to subscribers, the topic should be updated and plugin interceptors should be called even if the client connection closes ungracefully.

Actual behavior

The message is forwarded to subscribers but the topic is not updated and plugin interceptors are not called if the client connection closes ungracefully.

To Reproduce

We can reproduce the issue with the MQTT.js client in Firefox:

window.onbeforeunload = (event) => {  // called by the browser when the webpage closes
  event.preventDefault()
  mqttClient.publish("topic", "payload", { retain: true })
  return ""
}

Details

DC2-DanielKrueger commented 1 year ago

@xadh00m

What do you mean with "the topic is not updated"?

xadh00m commented 1 year ago

Hi @DC2-DanielKrueger,

The retained topic of the broker is not updated. Which means a new subscription to the topic returns the old value. The new value, which has been sent to the previous subscribers, is not retained..

DC2-DanielKrueger commented 1 year ago

I could not reproduce this by closing the channel right after the publish was sent. Do you know what the js client actually does? Does it sent a DISCONNECT or closes the tcp channel with FIN packet? Is the problem occurring consistently or rather flaky?