Skip to content

Conversation

@jbertram
Copy link
Contributor

@jbertram jbertram commented Dec 1, 2025

This commit ensures that MQTT 5 sessions using a session expiry interval of 0 are cleaned up after a broker restart. This includes:

  • Serialized state message in the $sys.mqtt.sessions queue
  • Any related $sys.mqtt.queue.qos2 queues
  • Any related subscription queues

To be clear, we can't simply inspect the session expiry interval when the session is created and make subscription queues non-durable because the session expiry interval can be changed on the session with the DISCONNECT packet at which point it would be impossible to potentially make the queue durable and persist all the messages.

This commit ensures that MQTT 5 sessions using a session expiry interval
of 0 are cleaned up after a broker restart. This includes:

 - Serialized state message in the $sys.mqtt.sessions queue
 - Any related $sys.mqtt.queue.qos2 queues
 - Any related subscription queues

To be clear, we can't simply inspect the session expiry interval when
the session is created and make subscription queues non-durable because
the session expiry interval can be changed on the session with the
DISCONNECT packet at which point it would be impossible to potentially
make the queue durable and persist all the messages.
@tabish121
Copy link
Contributor

Seeing a repeatable failure in test:org.apache.activemq.artemis.tests.integration.mqtt5.MQTT5Test#testResumeSubscriptionsAfterRestart

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:158)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:139)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:69)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:41)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:35)
	at org.junit.jupiter.api.Assertions.assertTrue(Assertions.java:195)
	at org.apache.activemq.artemis.tests.integration.mqtt5.MQTT5Test.testResumeSubscriptionsAfterRestart(MQTT5Test.java:235)

if (!state.isAttached() && sessionExpiryInterval > 0 && state.getDisconnectedTime() + (sessionExpiryInterval * 1000) < System.currentTimeMillis()) {
toRemove.add(entry.getKey());
if (!state.isAttached()) {
if (sessionExpiryInterval == 0) {
Copy link
Contributor

@tabish121 tabish121 Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it could be flattened into one if since it could be an Or on the next condition either its zero or its a positive value and trips the time limit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm investigating...

@jbertram jbertram marked this pull request as draft December 1, 2025 22:49
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