Skip to content

Apply isDup flag in MQTT5 buildMqttPubMessage (three builder paths) — fixes #283 - #284

Merged
popduke merged 2 commits into
apache:mainfrom
ImDanXie:fix/mqtt5-redelivery-dup-flag
Sep 24, 2026
Merged

popduke merged 2 commits into
apache:mainfrom
ImDanXie:fix/mqtt5-redelivery-dup-flag

Conversation

@ImDanXie

Copy link
Copy Markdown
Contributor

Re-delivered PUBLISH packets were built with DUP=0 — the isDup parameter of MQTT5ProtocolHelper#buildMqttPubMessage was accepted but never applied in any of its three builder paths (topic-alias first-use, topic-alias reuse, no-alias).

Per MQTT-3.3.1-1 ("The DUP flag MUST be set to 1 by the Client or Server when it attempts to re-deliver a PUBLISH packet"), re-delivery must carry DUP=1. Standards-compliant clients (e.g. the HiveMQ MQTT client) currently treat the re-delivery as a protocol error and disconnect — message loss in server-side bridge scenarios.

Full reproduction path and source-level analysis: #283 (opened as requested by @popduke).

Change

  • apply .dup(isDup) in all three MQTT5MessageBuilders.pub() paths;

Testing

Fixes #283

…ths)

Re-delivered PUBLISH packets were built with DUP=0, causing standards-compliant
clients (e.g. HiveMQ MQTT client) to treat the re-delivery as a protocol error
and disconnect — message loss in server-side bridge scenarios.

Per MQTT-3.3.1-1, the DUP flag MUST be set on re-delivery. The isDup parameter
was accepted but never applied in any of the three builder paths (topic-alias
first-use / topic-alias reuse / no-alias).

Fixes apache#283

Signed-off-by: DanXie <517964478@qq.com>
Adds qos1RedeliveryCarriesDupFlag to TransientSessionHandlerTest:
publish one QoS1 message, keep it in flight, advance past
ResendTimeoutSeconds, and assert the re-delivered PUBLISH carries
DUP=1 per [MQTT-3.3.1-1] while going through the topic-alias
reuse builder path. The handler is rebuilt with stubbed settings
because TenantSettings reads its values once at construction.

Verified against the unfixed MQTT5ProtocolHelper the new test
fails with 'DUP=1 expected true but found false'; with the fix
the full TransientSessionHandlerTest (52 tests) passes.

@popduke popduke left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx

@popduke
popduke merged commit eef5e3a into apache:main Sep 24, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants