Skip to content

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

Closed
jfallows wants to merge 2 commits into
test/mqtt-resubscribe-identicalfrom
claude/qos2-recovery-bound
Closed

jfallows wants to merge 2 commits into
test/mqtt-resubscribe-identicalfrom
claude/qos2-recovery-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.

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: binding-mqtt-kafka runtime 105 unit + 178 IT, spec KafkaIT 160 and MqttIT 140 (300 spec tests overall).
  • ./mvnw checkstyle:check is clean on both modules.

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

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3156. The stack was rebased onto the current develop, and the stack branches were renamed to feature/mqtt-shared-subscriptions-* because the build workflow only runs for pull requests whose base is develop, support/** or feature/**. The replacement has the same title and description. Head: feature/mqtt-shared-subscriptions-10-recovery-fetch-bound, base: feature/mqtt-shared-subscriptions-9-resubscribe-tests.


Generated by Claude Code

@jfallows jfallows closed this Nov 12, 2026
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