Skip to content

fix(binding-mqtt-kafka): compare message expiry interval in seconds - #3137

Merged
jfallows merged 2 commits into
fix/3130-mqtt-kafka-connack-maximum-qosfrom
fix/3131-mqtt-kafka-message-expiry-seconds
Nov 12, 2026
Merged

jfallows merged 2 commits into
fix/3130-mqtt-kafka-connack-maximum-qosfrom
fix/3131-mqtt-kafka-message-expiry-seconds

Conversation

@jfallows

Copy link
Copy Markdown
Contributor

Description

The MQTT Message Expiry Interval is in seconds, but the subscribe path compared it as milliseconds. MqttKafkaPublishFactory writes the interval unchanged into the 4-byte zilla:expiry header (seconds). MqttKafkaSubscribeFactory then computed timestamp(ms) + timeout(seconds) - now(ms) in both the live path and the retained replay path, and forwarded that millisecond count as the interval to the client. A message with an N-second interval was therefore dropped after about N milliseconds, and any message that survived carried a millisecond count in a seconds field.

MQTT 5.0 section 3.3.2.3.3: a message whose interval has passed before onward delivery starts must not be delivered to that subscriber, and the PUBLISH sent to a client carries the received interval minus the time the message waited on the server.

Changes, all in MqttKafkaSubscribeFactory:

  • The deadline is timestamp + seconds * 1000, compared against the current time in milliseconds, in the live path and in the retained replay path.
  • The zilla:expiry header stays in seconds, so records already in Kafka topics remain valid. The publish side is unchanged.
  • The interval forwarded to the client is the remaining time floored to whole seconds, so it never exceeds what remains. A message with under 1s remaining is delivered with interval 0, which MQTT 5 allows. A message is dropped only once its deadline has passed.

Spec scripts: subscribe.expire.message and subscribe.expire.message.fragmented (kafka side) were changed because they encoded the unit mix-up: they used zilla:expiry = 1 against a 1000 ms delta. The delta is now 5000 ms so the 1 second interval has clearly passed. New scripts cover a live message that waited part of its interval (4s interval, waited 1.5s, delivered with 2), a retained replay of the same, and a retained message whose interval has passed (dropped, later live message still delivered).

Fixes #3131

Stack (each PR is based on the previous branch):

PR Issue Branch Base
#3135 #3129 fix/3129-mqtt-per-connection-limits develop
#3136 #3130 fix/3130-mqtt-kafka-connack-maximum-qos fix/3129-mqtt-per-connection-limits
this PR #3131 fix/3131-mqtt-kafka-message-expiry-seconds fix/3130-mqtt-kafka-connack-maximum-qos
TBD #3132 fix/3132-mqtt-kafka-retained-tombstone fix/3131-mqtt-kafka-message-expiry-seconds
TBD #3133 fix/3133-mqtt-v4-clean-session-persistence fix/3132-mqtt-kafka-retained-tombstone

Test evidence

Test-first: after the test commit alone (against develop), MqttKafkaSubscribeProxyIT ran 58 tests with 2 failing: shouldReceiveMessageWithReducedExpiryInterval and shouldReceiveRetainedMessageWithReducedExpiryInterval, because the old code forwarded a millisecond count. The two expired-message tests (live and retained) passed on the old code as well and act as regression guards.

After the fix, rebased onto the PR 2 branch, ./mvnw clean verify -pl specs/binding-mqtt-kafka.spec,runtime/binding-mqtt-kafka (checkstyle and license checks included) passed:

  • specs/binding-mqtt-kafka.spec: 27 unit tests, MqttIT 97, KafkaIT 122
  • runtime/binding-mqtt-kafka: 10 unit tests, MqttKafkaSubscribeProxyIT 58, MqttKafkaSessionProxyIT 30, MqttKafkaPublishProxyIT 39

Notes

The rebase onto the PR 2 branch had no conflicts. No follow-ups found.


Generated by Claude Code

Correct the expire.message scripts so a one second interval has clearly
passed, and add scripts for a message that waited part of its interval,
and for the same cases on a retained replay.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoVeWBEApS7TUPZ4CA8
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: Message Expiry Interval is compared as milliseconds instead of seconds

2 participants