Skip to content

[BUG] Retain flag ignored — every PUBLISH stored as retained; zero-byte retained PUBLISH never deletes #6849

Description

@Aias00

Description

TopicRepository.add(topic, message) is called unconditionally for every inbound PUBLISH regardless of the retain bit (module-wide grep for isRetain/retain returns zero hits). A zero-byte retained PUBLISH should delete the retained message — that never happens.

Location

  • shenyu-protocol/shenyu-protocol-mqtt/src/main/java/org/apache/shenyu/protocol/mqtt/Publish.java:55
  • shenyu-protocol/shenyu-protocol-mqtt/src/main/java/org/apache/shenyu/protocol/mqtt/repositories/TopicRepository.java:34-37

Impact

Non-retained messages are persisted and redelivered to future subscribers as if they were retained (via Subscribe.sendSubMessage at Subscribe.java:72-77, which sends with retain=true). Violates MQTT-3.3.1.

Suggested fix

Read msg.fixedHeader().isRetain(); only call TopicRepository.add when retain is true; on a zero-byte retained PUBLISH, call TopicRepository.remove(topic).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions