Skip to content

mqtt: MQTT 3.1.1 Clean Session=0 does not keep session state, and session expiry conversion overflows #3133

Closed

Description

@jfallows

Problem

MQTT 3.1.1 Clean Session=0. The CONNECT path for MQTT 3.1.1 never sets a session expiry. MqttServerFactory assigns sessionExpiry only from the MQTT 5 Session Expiry Interval property (line ~3036) and later from the application's reply (line ~5838), so a 3.1.1 session has expiry 0 whatever the Clean Session flag says. mqtt-kafka treats expiry 0 as "the session ends when the connection closes" (an expiry signal with delay 0 and removal of the session record at close; this was established by reading the code and the first step is a test that confirms it). A 3.1.1 client that connects with Clean Session=0 therefore does not get its subscriptions or session state back. The existing 3.1.1 session scripts run against a mocked application, so nothing exercises this.

MQTT 3.1.1 section 3.1.2.4 (Clean Session) and section 4.1: with Clean Session=0 the server resumes the session from stored state and stores the session state after the client disconnects. The session lasts until the client connects with Clean Session=1.

MQTT 5 expiry conversion.

  • MqttKafkaSessionFactory (line ~585) converts with (int) SECONDS.toMillis(expiry), which overflows above about 24.8 days (2^31 ms).
  • MqttServerFactory (line ~3035) casts the Session Expiry Interval to int, so 0xFFFFFFFF becomes -1. MQTT 5.0 section 3.1.2.11.2 defines 0xFFFFFFFF as "the session does not expire".

Expected

  • A 3.1.1 CONNECT with Clean Session=0 creates a session that does not expire; Clean Session=1 keeps today's behavior (ends at disconnect).
  • Session expiry is carried as an unsigned 32-bit number of seconds and converted to milliseconds without overflow, in a long. 0xFFFFFFFF means no expiry and no expiry signal is scheduled for it.

Test plan (test-first)

Scripts that go through mqtt-kafka (not a mocked application) for:

  • 3.1.1 Clean Session=0: connect, subscribe, disconnect, reconnect with Clean Session=0 returns Session Present and the subscriptions; a Clean Session=1 connect discards them;
  • 3.1.1 Clean Session=1: state is removed at disconnect (unchanged);
  • 5.0 Session Expiry Interval of 0xFFFFFFFF and of a value above 2^31 milliseconds in seconds.

The first commit contains the failing scripts.

Notes

Cleanup of the per-session #offsets record and consumer-group offsets at expiry, and applying a Session Expiry Interval sent in DISCONNECT, are separate follow-ups. Found by a clause-by-clause conformance audit, by reading the code. Part of the MQTT conformance work under #512.

Activity

  1. added 3 commits that reference this issue on Nov 12, 2026
    029524c
    ea1b36e
    e447ddc
  2. self-assigned this
    on Nov 12, 2026
  3. added a commit that references this issue on Nov 17, 2026
    b1a53e9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions