You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@artemis.apache.org by "Justin Bertram (Jira)" <ji...@apache.org> on 2026/08/20 20:06:00 UTC

[jira] [Comment Edited] (ARTEMIS-6191) MQTT QoS 1 messages are delivered out of order

    [ https://issues.apache.org/jira/browse/ARTEMIS-6191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18106405#comment-18106405 ] 

Justin Bertram edited comment on ARTEMIS-6191 at 8/20/26 8:05 PM:
------------------------------------------------------------------

The changes for ARTEMIS-6189 (which include the {{OperationContext}} fix) [have been merged|https://github.com/apache/artemis/pull/6613]. Can you test again using the latest [snapshot build|https://artemis.apache.org/components/artemis/documentation/hacking-guide/#snapshot-builds]?


was (Author: jbertram):
The changes for ARTEMIS-6189 [have been merged|https://github.com/apache/artemis/pull/6613]. Can you test again using the latest [snapshot build|https://artemis.apache.org/components/artemis/documentation/hacking-guide/#snapshot-builds]?

> MQTT QoS 1 messages are delivered out of order
> ----------------------------------------------
>
>                 Key: ARTEMIS-6191
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-6191
>             Project: Artemis
>          Issue Type: Bug
>          Components: Broker
>    Affects Versions: 2.55.0
>            Reporter: Boris Alekseev
>            Priority: Critical
>
> Summary: MQTT 3.1.1 QoS 1 messages can be delivered out of order under concurrent load
> h2. Description
> Apache ActiveMQ Artemis 2.55.0 can intermittently deliver MQTT 3.1.1 QoS 1 messages to a subscriber in a different order from the order in which they were received from the publisher.
> All messages are delivered without duplicates or disconnects. The failure occurs more often when several independent tests use the broker concurrently.
> h2. Environment
> * Apache ActiveMQ Artemis 2.55.0, the latest release at the time of verification: https://activemq.apache.org/components/artemis/download/
> * Official Docker image: {{apache/artemis:2.55.0-alpine}}
> * MQTT 3.1.1
> * QoS 1 for the subscription and publications
> * AIO journal
> h2. Steps to reproduce
> # Connect one MQTT 3.1.1 client.
> # Subscribe to a unique topic at QoS 1.
> # Sequentially publish payloads {{0, 1, 2, 3, 4}} from the same client to the same topic at QoS 1, waiting for each {{PUBACK}}.
> # Read the five messages from the subscription.
> Running several independent instances concurrently makes the failure easier to reproduce. Every instance uses a unique client identifier and topic.
> h2. Expected result
> 0, 1, 2, 3, 4
> MQTT 3.1.1 requires a server to forward messages from a given client on an Ordered Topic in the order in which they were received. Requirement MQTT-4.6.0-6: https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718105
> h2. Actual result
> With Artemis 2.55.0, the MQTT 3.1.1 test failed 4 times in 200 repetitions with 8 concurrent test processes.
> Observed orders:
> 0, 2, 1, 3, 4
> 1, 0, 2, 3, 4
> 1, 2, 0, 3, 4
> 0, 1, 3, 2, 4
> The same test using MQTT 5.0 did not fail in 500 repetitions with the same concurrency. This does not prove that MQTT 5.0 is unaffected because both protocol versions share the broker's outgoing delivery path.
> h2. zMQTT test
> * Shared message-ordering test: https://github.com/faststream-community/zMQTT/blob/ed7dc1caac66e753907c00476fd7dcc374235a5e/tests/test_brokers/_base.py#L218-L225
> * Artemis MQTT 3.1.1 and MQTT 5.0 test bindings: https://github.com/faststream-community/zMQTT/blob/ed7dc1caac66e753907c00476fd7dcc374235a5e/tests/test_brokers/test_artemis.py#L96-L105
> h2. Public CI results
> These earlier public runs used Artemis 2.44.0 and demonstrate the same intermittent failure:
> * Received {{1, 2, 0, 3, 4}}; result {{1 failed, 567 passed, 10 skipped}}: https://github.com/faststream-community/zMQTT/actions/runs/32063447688/job/95489785526
> * Received {{1, 0, 2, 3, 4}}; result {{1 failed, 567 passed, 10 skipped}}: https://github.com/faststream-community/zMQTT/actions/runs/32062653055/job/95487265306
> * Received {{0, 2, 1, 3, 4}}; result {{1 failed, 567 passed, 10 skipped}}: https://github.com/faststream-community/zMQTT/actions/runs/32062653055/job/95487265382
> * Received {{0, 2, 3, 4, 1}}; result {{1 failed, 567 passed, 10 skipped}}: https://github.com/faststream-community/zMQTT/actions/runs/31960911272/job/95198646246
> The same zMQTT commit also passed in another CI run, confirming that the failure is timing-dependent: https://github.com/faststream-community/zMQTT/actions/runs/32063266180
> h2. Suspected area
> The exact root cause is not confirmed.
> In Artemis 2.55.0, {{MQTTProtocolHandler.sendToClient()}} defers socket writes through {{StorageManager.afterCompleteOperations()}}: https://github.com/apache/artemis/blob/2.55.0/artemis-protocols/artemis-mqtt-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/mqtt/MQTTProtocolHandler.java#L408-L423
> The selected {{OperationContext}} is thread-local: https://github.com/apache/artemis/blob/2.55.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/OperationContextImpl.java#L37-L76
> MQTT packets are processed by an {{Actor}} backed by the server thread pool. ARTEMIS-6189 changes the current implementation to restore the session operation context before processing every actor task: https://github.com/apache/artemis/pull/6613
> This is consistent with completion callbacks for consecutive messages being associated with different operation contexts and completing out of order. It may also explain why the faster MQTT 3.1.1 path reproduces the race more readily than MQTT 5.0.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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