Skip to content

fix(binding-mqtt-kafka): bound the QoS 2 recovery fetch at the log end - #3156

Merged
jfallows merged 2 commits into
feature/mqtt-shared-subscriptions-9-resubscribe-testsfrom
feature/mqtt-shared-subscriptions-10-recovery-fetch-bound
Nov 17, 2026
Merged

jfallows merged 2 commits into
feature/mqtt-shared-subscriptions-9-resubscribe-testsfrom
feature/mqtt-shared-subscriptions-10-recovery-fetch-bound

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

When a client reconnects with a restored shared subscription, a QoS 2 ticket in PUBLISH-sent state re-fetches its record by exact offset (a merged FETCH_ONLY stream, KafkaRecoveryProxy in MqttKafkaSubscribeFactory). That fetch had no latestOffset bound. Reasoned from the code, a ticket offset exactly at the log end makes the fetch long-poll, and one past the end triggers the Kafka client's out-of-range reset to earliest, so the first record has a different offset and the ticket is dropped as a mismatch.

This change sets stableOffset and latestOffset to KafkaOffsetType.HISTORICAL on the recovery fetch partition, so the stream ends at the log end instead of waiting for new data.

Pattern mirrored: the HISTORICAL marker already used by HttpKafkaWithFetchResult and the GrpcKafkaWith*Result classes. In KafkaCacheClientFetchFactory a fetch carrying it ends once the cursor passes the group's latest offset, and KafkaMergedFactory treats HISTORICAL as "end when the fetch streams end".

Commits

  • test(binding-mqtt-kafka): all six recovery fetch scenarios now assert the bounded begin (.partition(0, 5, -2)), plus a new subscribe.shared.recover.qos2.publish.sent.beyond.end scenario (kafka and mqtt scripts, spec ITs, runtime IT). The scenario is wire-identical to .missing apart from a log end below the ticket offset, so the real coverage is the begin assertion.
  • fix(binding-mqtt-kafka): the two-line change in newKafkaRecoveryStream.

Part of #1801

This fix is not verified end to end. The evidence is spec-level only (below). A real-broker reproduction did not reproduce the reasoned behaviour, so this PR does not claim to fix any observed stall.

Stack

Layer 10 of the stack of PRs for #1801, based on #3155 (layer 9). See #3154 for the full table.

Test evidence

  • Before the fix, the 7 recovery scenarios in MqttKafkaSubscribeProxyIT failed (timeouts and store assertion mismatches). After the fix they pass.
  • ./mvnw clean install -pl specs/binding-mqtt.spec,specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka passes in full on this base.
  • ./mvnw checkstyle:check is clean on both modules.
  • The full reactor build of this tip (./mvnw clean install): BUILD SUCCESS.

Real-broker reproduction (Kafka 4.1.1, examples/mqtt.kafka.proxy, a stdlib Python MQTT 5 client)

  1. Harness check, no topic recreate: a QoS 2 PUBLISH is received but never PUBREC'd, then the client drops and reconnects with Clean Start 0. The message is redelivered with DUP=1 and the same packet id, followed by the next message. The recovery path works against the broker.
  2. Beyond-end attempt: the same flow, but mqtt-messages was deleted and recreated before reconnecting (log end 0, ticket offset 3). The reconnect gets session present=1, but no PUBLISH arrives within 45s on the image without this change, and none within 40s on the image with it. The behaviour is identical, so the HISTORICAL bound has no observable effect here and the reasoned behaviour was not reproduced.
  3. Controls on the recreated topic: a fresh client with no ticket receives its message in 0.01-0.02s, both in a different share group and in the same group. So the gateway and the share group work, and only the client with the pending ticket stalls.

The topic-recreate reproduction cannot put the ticket past the log end that the recovery fetch sees. The Zilla cache keeps the pre-recreate records (offsets 0-4), and the memory store is the only store here, so tickets do not survive a restart with a fresh cache. A reproduction of the target condition probably needs a persistent store. The Kafka client's out-of-range reset path was not exercised end to end. The stall seen in step 2 occurs on both images and is not attributed to this change. Its cause is still being investigated.


Generated by Claude Code

@jfallows
jfallows force-pushed the feature/mqtt-shared-subscriptions-10-recovery-fetch-bound branch from 021fa00 to 7f4f4fd Compare November 17, 2026 18:36
@jfallows
jfallows merged commit c561d3c into develop Nov 17, 2026
6 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