You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@artemis.apache.org by "k-krawczyk (via GitHub)" <gi...@apache.org> on 2026/05/30 07:16:15 UTC

[PR] ARTEMIS-6085 Fix NPE from race in MQTTStateManager.getSessionState [artemis]

k-krawczyk opened a new pull request, #6480:
URL: https://github.com/apache/artemis/pull/6480

   ## What
   Fixes a `NullPointerException` thrown from `MQTTProtocolHandler#handleLinkStealing()` (`getSessionState(clientID).getSession()`).
   
   ## Root cause
   `MQTTStateManager.getSessionState(String)` used a non-atomic `containsKey()` + `get()` on a `ConcurrentHashMap`. During link stealing (two connections sharing a client ID), `removeSessionState()` can run on another thread between the two calls, so `get()` returns `null` and the caller dereferences it with `.getSession()`.
   
   The race is still present on `main`.
   
   ## Fix
   Replace the `containsKey()/get()/put()` block with an atomic `computeIfAbsent()` — a get-or-create that can never return `null`. Behaviour is otherwise unchanged.
   
   ## Test
   Adds `MQTTStateManagerTest`, a concurrency regression test that runs `getSessionState()` against concurrent `removeSessionState()` on the same client ID and asserts a non-null result. It fails (NPE/null) on the pre-fix code in ~1s and passes after the fix. The full `artemis-mqtt-protocol` module suite is green (12/12).
   
   JIRA: https://issues.apache.org/jira/browse/ARTEMIS-6085


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org
For additional commands, e-mail: issues-help@artemis.apache.org


Re: [PR] ARTEMIS-6085 Fix NPE from race in MQTTStateManager.getSessionState [artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram merged PR #6480:
URL: https://github.com/apache/artemis/pull/6480


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org
For additional commands, e-mail: issues-help@artemis.apache.org


Re: [PR] ARTEMIS-6085 Fix NPE from race in MQTTStateManager.getSessionState [artemis]

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on PR #6480:
URL: https://github.com/apache/artemis/pull/6480#issuecomment-4594525760

   @k-krawczyk many thanks for the great contribution!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org
For additional commands, e-mail: issues-help@artemis.apache.org