Repository navigation
fix(binding-mqtt): keep the session for mqtt 3.1.1 clean session 0 - #3147
Merged
jfallows merged 4 commits intoNov 12, 2026
Conversation
jfallows
force-pushed
the
fix/3133-mqtt-v4-clean-session-persistence
branch
from
November 12, 2026 20:41
9022896 to
4fecf10
Compare
Contributor
Author
|
CI on This is not caused by this PR:
The test was introduced lower in the stack (#3135), so I'm leaving it to that layer rather than changing a test here. I'm not skipping, disabling or retrying anything. This PR will pick up whatever fix lands there when the stack is restacked. Generated by Claude Code |
…sion expiry Add network and application scripts asserting the session expiry carried to the application stream for MQTT 3.1.1 Clean Session=0 (never expires), Clean Session=1 (zero) and the MQTT 5 Session Expiry Interval 0xFFFFFFFF. Add mqtt-kafka scripts for a non expiring session that is reconnected with its subscriptions and publishes no expiry signal, an expiry interval above 2^31 milliseconds, and expiry zero at close. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6wezgVqyaf2mPbd8
MQTT 3.1.1 section 3.1.2.4 keeps the session until the client connects with Clean Session=1, so a connect with Clean Session=0 now carries a session expiry of 0xFFFFFFFF (never expires) to the application, while Clean Session=1 keeps expiry 0. The mqtt-kafka session no longer sends an expiry signal at close, abort or connect for a session that never expires, and echoes the received expiry unchanged instead of converting through milliseconds. Expiry seconds are read as unsigned and converted to milliseconds in a long; the int32 signal delay saturates at Integer.MAX_VALUE with the exact deadline in expireAt. The will delay clamp treats never expires as unbounded. A DISCONNECT Session Expiry Interval is compared as unsigned. Fixes #3133 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6wezgVqyaf2mPbd8
…ion and will with no session expiry Add a clean start reconnect that clears the state stored by a non expiring session, and a will delivered on abort for a session that never expires. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6wezgVqyaf2mPbd8
…cripts Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SiHVoW6wezgVqyaf2mPbd8
jfallows
force-pushed
the
fix/3133-mqtt-v4-clean-session-persistence
branch
from
November 12, 2026 21:18
4fecf10 to
83657f9
Compare
This was referenced Nov 12, 2026
fix(binding-mqtt-kafka): apply qos and no local conditions to retained replay on filter change
#3159
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What and why. MQTT 3.1.1 section 3.1.2.4 (Clean Session) and section 4.1 say that with Clean Session=0 the server resumes the session from stored state and keeps it until the client connects with Clean Session=1. Until now the server never set a session expiry for 3.1.1, so every 3.1.1 session had expiry 0. mqtt-kafka treats expiry 0 as "ends when the connection closes": it sends an expiry signal with delay 0, and the session record is removed. A 3.1.1 client with Clean Session=0 therefore lost its subscriptions. I confirmed this with a failing test before changing anything.
MQTT 5.0 section 3.1.2.11.2 defines a Session Expiry Interval of 0xFFFFFFFF as "the session does not expire". The old conversion
(int) SECONDS.toMillis(expiry)overflowed above about 24.8 days.Changes
MqttSessionBeginEx.expirystays int32 on the wire and is read as unsigned. -1 means never expires, so there is no IDL change.MqttKafkaSessionFactory):long.MqttServerFactorynow compares as unsigned. It does not apply the DISCONNECT expiry, which is still out of scope.What is NOT delivered. The expiry signals (
MqttExpirySignal,MqttWillSignal) are persisted in the Kafka sessions topic and have no version field, so I did not change their layout.delaystays int32 milliseconds and saturates atInteger.MAX_VALUE. The exact deadline travels in the int64expireAtof the at-close signal. The cross-instance "expire later" path (expireAt = -1, reader computes now + delay) is therefore capped at about 24.8 days. Widening the signal layout needs a compatible design and is a follow-up.Fixes #3133
Stack
fix/3129-mqtt-per-connection-limitsdevelopfix/3130-mqtt-kafka-connack-maximum-qosfix/3129-mqtt-per-connection-limitsfix/3131-mqtt-kafka-message-expiry-secondsfix/3130-mqtt-kafka-connack-maximum-qosfix/3132-mqtt-kafka-retained-tombstonefix/3131-mqtt-kafka-message-expiry-secondsfix/3133-mqtt-v4-clean-session-persistencefix/3132-mqtt-kafka-retained-tombstoneThis branch is restacked by rebase onto the current head of #3146 (
18b0225e5), replaying only this PR's four commits. The rebase had no conflicts.Test evidence
Tests were committed first (
test(...)commits precede thefix(...)commit).session.connect.non.clean.start(application expiry -1), v4session.connect.clean.start(expiry 0), v5session.connect.with.session.expiry.never(0xFFFFFFFF becomes -1).session.close.reconnect.non.expiring: connect, store subscription state, close, reconnect gets the state back; no expiry signals.session.close.expire.session.state.large.interval: 3000000 s sendsdelay = 2147483647andexpireAt = 3000001000.session.close.expire.session.state.immediately: expiry 0 sends delay 0 at close (unchanged behavior).session.close.reconnect.clean.start: a Clean Session=1 reconnect clears the state stored by a non-expiring session.session.will.message.abort.deliver.will.non.expiring: a will delivered on abort for a never-expiring session.publishQosMax(1)on the session reply. The session matcher ignorespublishQosMaxunless a script sets it, so this keeps them valid now that fix(binding-mqtt-kafka): advertise maximum qos when qos 2 publish is disabled #3136 enforces it. No other script needed changing../mvnw clean verify -am, checkstyle, license and jacoco on) forspecs/binding-mqtt.spec,runtime/binding-mqtt,specs/binding-mqtt-kafka.specandruntime/binding-mqtt-kafka, on this branch rebased onto fix(binding-mqtt-kafka): remove the retained message on a zero-byte retained publish #3146: BUILD SUCCESS, 0 failures (binding-mqtt runtime 452 tests, binding-mqtt-kafka runtime 376 tests, binding-mqtt spec 441, binding-mqtt-kafka spec 234). My four modules ran their tests; only unchanged upstream modules came from the build cache. The earlier redserver.v5.SubscribeITin CI came from the lower layer (fix(binding-mqtt): scope maximum packet size and publish qos max to the connection #3135) and passes here.buildmodule (license mapping formanagerandzpm-maven-plugin). That is an environment issue.Notes and follow-ups
delayis int32 as well), so cross-instance expiry beyond about 24.8 days works.#offsetsrecord and consumer-group offsets at expiry. A never-expiring session keeps them indefinitely, so this matters more now.isKafkaOpenguard inMqttKafkaSessionFactory.KafkaSessionStream) is not in this stack yet. Expect to reconcile it when the stack is rebased ontodevelop.🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoW6wezgVqyaf2mPbd8