You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Rich T (Jira)" <ji...@apache.org> on 2025/06/23 08:57:00 UTC
[jira] [Commented] (ARTEMIS-5540) clarify doc for MQTT default session expiry interval
[ https://issues.apache.org/jira/browse/ARTEMIS-5540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17985267#comment-17985267 ]
Rich T commented on ARTEMIS-5540:
---------------------------------
Hey [~jbertram] unfortunately I don't have a test but the problem appears to be in {{MQTTSession#stop}} where there is different logic for MQTT3 vs MQTT5. For {{!MQTT5}} {{removeSessionState}} is only called for clean sessions the test you referenced seems to cover MQTT5.
> clarify doc for MQTT default session expiry interval
> ----------------------------------------------------
>
> Key: ARTEMIS-5540
> URL: https://issues.apache.org/jira/browse/ARTEMIS-5540
> Project: ActiveMQ Artemis
> Issue Type: Bug
> Affects Versions: 2.41.0
> Reporter: Rich T
> Priority: Major
> Fix For: 2.42.0
>
>
> The {{MQTTStateManager}} {{scanSessions}} logic only seems to clear out sessions if the timeout is greater than 0 but this doesn't align with the documentation:
> {quote}The default {{defaultMqttSessionExpiryInterval}} is {{-1}} which means no MQTT 3.x session states will be expired and no MQTT 5 session states which do not pass their own session expiry interval will be expired. Otherwise it represents the number of *seconds* which must elapse after the client has disconnected before the broker will remove the session state.{quote}
> Based on this information I would expect a value of {{0}} to expire a disconnected session on next {{scanSessions}} execution but instead a value of {{0}} appears to behave like a value of {{-1}}.
> Copy of code in question:
> {code:java}
> public void scanSessions() {
> List<String> toRemove = new ArrayList();
> for (Map.Entry<String, MQTTSessionState> entry : sessionStates.entrySet()) {
> MQTTSessionState state = entry.getValue();
> logger.debug("Inspecting session: {}", state);
> int sessionExpiryInterval = state.getClientSessionExpiryInterval();
> if (!state.isAttached() && sessionExpiryInterval > 0 && state.getDisconnectedTime() + (sessionExpiryInterval * 1000) < System.currentTimeMillis()) {
> toRemove.add(entry.getKey());
> }
> if (state.isWill() && !state.isAttached() && state.isFailed() && state.getWillDelayInterval() > 0 && state.getDisconnectedTime() + (state.getWillDelayInterval() * 1000) < System.currentTimeMillis()) {
> state.getSession().sendWillMessage();
> }
> }
> for (String key : toRemove) {
> try {
> MQTTSessionState state = removeSessionState(key);
> if (state != null) {
> if (state.isWill() && !state.isAttached() && state.isFailed()) {
> state.getSession().sendWillMessage();
> }
> state.getSession().clean(false);
> }
> } catch (Exception e) {
> MQTTLogger.LOGGER.failedToRemoveSessionState(key, e);
> }
> }
> } {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@activemq.apache.org
For additional commands, e-mail: issues-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact