Skip to content

fix(binding-mqtt-kafka): remove the retained message on a zero-byte retained publish - #3146

Merged
jfallows merged 3 commits into
fix/3131-mqtt-kafka-message-expiry-secondsfrom
fix/3132-mqtt-kafka-retained-tombstone
Nov 12, 2026
Merged

jfallows merged 3 commits into
fix/3131-mqtt-kafka-message-expiry-secondsfrom
fix/3132-mqtt-kafka-retained-tombstone

Conversation

@jfallows

@jfallows jfallows commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

A PUBLISH with RETAIN=1 and a zero-byte payload must remove the retained message for that topic: MQTT 5.0 section 3.3.1.3 and [MQTT-3.3.1-7], and MQTT 3.1.1 [MQTT-3.3.1-10] and [MQTT-3.3.1-11]. MqttKafkaPublishFactory wrote the retained-topic record with the payload as received, so a zero-length payload became an empty value rather than a Kafka tombstone (null value). The retained topic is log-compacted and keyed by the MQTT topic name, so compaction kept the empty value as the latest record, and a later subscriber's retained replay could be sent a zero-length message.

What changes:

  • MqttKafkaPublishFactory: a retained publish with a null or zero-length payload writes a null value (tombstone) keyed by the topic to the retained topic. The record on the messages topic is unchanged, so live subscribers still receive a normal zero-length message.
  • MqttKafkaSubscribeFactory (KafkaRetainedProxy.onKafkaData): retained replay skips a single-frame null or empty value, including empty-valued records already present in a retained topic written by older versions. It sits before the seconds-based expiry computation and does not change it.

The compacted retained topic keyed by topic name is the existing design and is unchanged.

Fixes #3132

Stack

# PR Branch Base
1 #3129 / #3135 fix/3129-mqtt-per-connection-limits develop
2 #3130 / #3136 fix/3130-mqtt-kafka-connack-maximum-qos fix/3129-mqtt-per-connection-limits
3 #3131 / #3137 fix/3131-mqtt-kafka-message-expiry-seconds fix/3130-mqtt-kafka-connack-maximum-qos
4 #3132 / #3146 (this PR) fix/3132-mqtt-kafka-retained-tombstone fix/3131-mqtt-kafka-message-expiry-seconds
5 #3133 / #3147 fix/3133-mqtt-v4-clean-session-persistence fix/3132-mqtt-kafka-retained-tombstone

Test evidence

Test-first: the scripts were committed before the fix.

  • Failed first: MqttKafkaPublishProxyIT.shouldPublishEmptyRetainedMessageAsTombstone matched every step up to the final read zilla:data.null on mqtt-retained and then never saw it, because the unfixed proxy wrote an empty value.
  • New scripts (mqtt and kafka sides): publish.empty.retained.message, subscribe.retained.tombstone, subscribe.retained.empty.value, subscribe.skip.removed.retained.message. The publish scenario publishes a retained message, then a retained zero-byte message, and asserts the normal record on the messages topic and a null value on the retained topic. The subscribe scenarios assert that a subscriber after the removal receives no retained message, and that replay skips a null value and an empty value.
  • New ITs: KafkaIT +3, MqttIT +2, MqttKafkaPublishProxyIT +1, MqttKafkaSubscribeProxyIT +2, DuplexIT +2.

Verify on the current head, clean, with -am:
./mvnw clean verify -pl runtime/engine,specs/binding-kafka.spec,specs/binding-mqtt.spec,runtime/binding-mqtt,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka -am

  • Result: BUILD SUCCESS, 0 failures, including checkstyle and license checks.
  • binding-mqtt-kafka.spec: 27 unit tests and 224 ITs.
  • binding-mqtt-kafka.conf: 15 tests.
  • binding-mqtt-kafka runtime: 10 unit tests and 130 ITs.
  • binding-mqtt.spec and binding-mqtt runtime (where the session matcher lives): 0 failures. The scripts added here use publish and subscribe streams, not session streams, so they are not affected by the enforced publish QoS maximum.
  • binding-kafka.spec (44 scripts using write zilla:data.empty, run as the other module consuming the shared k3po extension): 0 failures. In this last run the engine and binding-kafka.spec modules were restored from the build cache because their inputs had not changed since an earlier uncached run, which also passed: a clean install of runtime/engine (310 unit tests, 264 ITs, skips are existing @Ignores).

Engine test-extension change (first commit)

The k3po zilla extension could read a null data value (read zilla:data.null) but could not write one, so a script could not play a peer that sends a data frame with a null payload. This PR adds write zilla:data.null:

  • WriteNullDataHandler, registered in ZillaBehaviorSystem and listed among the write configs in ZillaTypeSystem, mirroring the empty-data write handler and the null-data read handler.
  • ZillaTarget now flushes a null buffer that carries no extension; previously it only flushed one that carried an extension.
  • Coverage: a write/read round trip in each direction in DuplexIT, next to the empty-data ones.

The change is confined to the engine test tree; there is no production engine code.

Notes and follow-ups

  • This module has no MQTT v4/v5 script split. The MQTT version is not visible at the mqtt-kafka layer, so one script set covers both versions; the v4/v5 split lives in binding-mqtt.
  • Replay skipping is limited to single-frame null or empty values, which is all a compacted retained record can be.
  • Rebase notes: KafkaIT and MqttIT conflicted with PR 3 only because both appended methods at the end of the class; both sets of tests are kept. The stack was later restacked onto PR 3's new head without conflicts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoWUyUFdeUruH6smCc8

Copy link
Copy Markdown
Contributor Author

CI on 2f309d0 is red, and the failure is not from this PR's changes.

  • Build (25) fails in runtime/binding-mqtt failsafe: server.v5.SubscribeIT.shouldCompleteDroppedQoS2MessageExceedingMaximumPacketSize times out after 10 seconds. It is the only failure (109 run, 1 error).
  • Examples is the aggregate gate: its setup job was skipped because Build (25) failed, so it has no separate cause.

Why it isn't this PR's:

  • The test method is not in this branch, nor in fix/3130-mqtt-kafka-connack-maximum-qos or fix/3131-mqtt-kafka-message-expiry-seconds. It exists only on fix/3129-mqtt-per-connection-limits, from commits added after the lower PRs were cut.
  • This PR touches runtime/binding-mqtt-kafka, its specs and the engine test tree, not binding-mqtt.
  • ./mvnw clean verify of runtime/binding-mqtt on this head passed locally.
  • The same test failed on fix(binding-mqtt-kafka): compare message expiry interval in seconds #3137.

Nothing to fix on this branch. It needs restacking onto the updated PR below it, after which CI will run again.


Generated by Claude Code

The k3po zilla extension can read a null data value but cannot write one,
so a script cannot play a peer that sends a data frame with a null payload.
Register write zilla:data.null with a WriteNullDataHandler, let the target
flush a null buffer that carries no extension, and cover it with a
write/read round trip in each direction in DuplexIT.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoWUyUFdeUruH6smCc8
…etained publish

A retained PUBLISH with a zero-length payload now writes a null value
(tombstone) keyed by the topic to the retained topic, and retained replay
skips null and empty values, including empty-valued records written by
older versions. The record on the messages topic is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoWUyUFdeUruH6smCc8
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.

mqtt-kafka: zero-byte retained PUBLISH does not remove the retained message

2 participants