Skip to content

fix(binding-mqtt-kafka): acknowledge qos1 publish only as far as kafka has acknowledged it - #3295

Merged
jfallows merged 5 commits into
developfrom
fix/3289-mqtt-kafka-publish-ack-window
Nov 16, 2026
Merged

jfallows merged 5 commits into
developfrom
fix/3289-mqtt-kafka-publish-ack-window

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

QoS 1 PUBLISH packets were acknowledged (PUBACK reason 0) as soon as Zilla received them, not when Kafka had acknowledged the produce. Under a slow broker, clients were told messages were accepted while they sat in a growing backlog, and an acknowledged backlog is lost if the process stops.

Two defects, fixed in two commits.

1. binding-mqtt-kafka: window acknowledge ignored the produce acknowledge

With retain available, doMqttWindow derived the MQTT-side acknowledge from the smaller of the messages and retained stream maximums and the smaller of their credit budgets. The cache client holds the messages stream's acknowledge at its oldest unacknowledged byte and grows its maximum by the unacknowledged bytes, so that stream's budget stays constant. The retained stream acknowledges each flush at once. The derived acknowledge therefore reached the received sequence regardless of Kafka, and the MQTT server sent each PUBACK on receipt.

The acknowledge is now derived from the larger unacknowledged byte count of the streams, and the maximum from the smaller budget plus that count. Without retain this equals the previous result. Pattern mirrored: KafkaMergedFactory.doMergedInitialWindow (maximum unacknowledged, minimum budget, maximum = budget + unacknowledged). A stream re-begun after a reset starts with the credit budget only, not the unacknowledged bytes of the stream it replaces.

2. binding-kafka: produce acknowledgement flushed to only one cache server member

Once real acknowledgements gate PUBACKs, a second defect becomes visible. The cache server produce fan remembered the last acknowledged offset it had flushed on the fan, not per member. A fan has one member per cache client fan (one per engine worker), so after the first member was flushed for an acknowledged offset every other member was skipped for it and never learned its entries were acknowledged. A publisher waiting on those entries, for example a QoS 1 client at its in-flight limit, stalled. The last flushed offset is now tracked per member.

Evidence (real broker, examples/mqtt.kafka.proxy, Kafka limited to 1 CPU)

  • Before: 20,000 PUBACKs reason 0 within about 10 s while Kafka took about 300 records/s; the records by key appeared only after 90 s to 5 min. After a broker pause the process crashed and about 1.8M acknowledged records never reached Kafka.
  • After defect 1: the ingest is paced by Kafka (PUBACKs track what Kafka takes) instead of about 1.5M PUBACKs against about 300/s.
  • Stall (defect 2): a fresh publisher after a heavy ingest got no PUBACKs in 5 of 6 runs before the second fix and in 0 of 6 after.

Tests

  • New runtime IT MqttKafkaPublishProxyIT.shouldPublishQos1RetainAvailableServerSentResetInFlight with paired mqtt and kafka scripts and spec-level MqttIT/KafkaIT methods: a produce reset while QoS 1 packets are unacknowledged must fail those packets with reason 0x83. It failed before the fix and passes after.
  • ./mvnw clean verify -pl runtime/binding-mqtt-kafka (168 ITs) and runtime/binding-kafka (229 unit tests, 469 ITs) pass with checks on.
  • No IT covers defect 2: it needs two members on one cache server fan, which only arise across engine workers, and multi-worker ITs are not used in this repository.

Not addressed

  • Records per Kafka batch: on this example every record in mqtt-devices was in its own batch, with -F 1 and with -F 1000 alike. Not changed here.
  • Under heavy throttled load I observed two crashes in the produce cache (an IndexOutOfBoundsException in segment compaction, and a SIGSEGV after a broker pause). I have not retested them with these fixes.

Fixes #3289


Generated by Claude Code

…tain available

Adds a paired mqtt and kafka script scenario for ten 1 KB QoS 1 publishes
with retain available, with spec-level and runtime ITs. These pass against
the current code; the window acknowledge defect in #3289 is not yet
observable from the scripts.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…resets with retain available

A produce stream reset while QoS 1 packets are not yet acknowledged by Kafka
must fail those packets. With retain available and a produce stream that grows
its maximum while holding its acknowledge, the proxy treats the packets as
acknowledged, so no failure is reported (#3289). The runtime IT fails until the
window acknowledge is derived from the unacknowledged bytes of both streams.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…a has acknowledged it

With retain available the publish window acknowledge was derived from the
smaller of the messages and retained stream maximums and the smaller of their
credit budgets. A stream that holds its acknowledge and grows its maximum by its
unacknowledged bytes keeps a constant budget, so the derived acknowledge reached
the received sequence regardless of what Kafka had acknowledged and every
QoS 1 publish was acknowledged on receipt.

Derive the acknowledge from the larger unacknowledged byte count of the streams
and the maximum from the smaller budget plus that count. A stream re-begun after
a reset starts with the credit budget only, not the unacknowledged bytes of the
stream it replaces.

Fixes #3289

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
…er member

The cache server produce fan remembered the last acknowledged partition offset
it had flushed on the fan, not on each member. A fan has one member per cache
client fan, one per engine worker, so once the first member was flushed for an
acknowledged offset every other member was skipped for that acknowledgement and
never learned that its own entries were acknowledged. The entries stayed
unacknowledged, so a producer waiting on them, for example a QoS 1 publisher
holding its in-flight limit, stalled until a later acknowledgement happened to
reach the member first.

Track the last flushed acknowledged offset per member.

No IT covers this: it needs two members on one server fan, which only arise
across engine workers. Verified on a real broker with 6 stack runs of a
throttled ingest followed by a fresh publisher: it stalled in 5 of 6 runs
before and in 0 of 6 after.

Refs #3289

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoTtPnwEYaRNAuVJZAW
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: QoS 1 PUBACK (reason 0) returned for messages that are not in Kafka after high-rate ingest

2 participants