Skip to content

mqtt-kafka: a QoS 2 PUBLISH crashes the engine (NoSuchElementException in KafkaOffsetCommitStream.onKafkaWindow) #3303

Description

@ankitk-me

Describe the bug

On develop (e5d8347), the first QoS 2 PUBLISH from an MQTT 5 client stops the Zilla engine. The client gets CONNACK 0 and sends
the PUBLISH, but no PUBREC comes back and the connection is lost. Zilla logs an AgentTerminationException caused by
NoSuchElementException in MqttKafkaPublishFactory$KafkaOffsetCommitStream.onKafkaWindow, then ENGINE_STOPPED.

It happened on every QoS 2 publish we tried, on freshly created stacks: 6 crashes in 6 attempts. The message itself
is written to Kafka (one record), but the client never gets a PUBREC, so a real client would resend it after
reconnecting. QoS 0 and QoS 1 publishes work, and so do QoS 2 subscriptions fed by QoS 1 publishers.

To Reproduce

  1. Start examples/mqtt.kafka.proxy from scratch with a develop image
    (docker compose down -v && docker compose up -d). Wait for ENGINE_STARTED.
  2. Publish one QoS 2 message:
    docker run --rm --network zilla-mqtt-kafka-proxy_default eclipse-mosquitto:2.0 \
      mosquitto_pub -d -h zilla.examples.dev -p 7183 -V mqttv5 -i "q2-$(date +%s)$RANDOM" -q 2 -t device/q2 -m one
  3. Check the Zilla log:
    docker compose logs zilla | grep -E 'AgentTerminationException|ENGINE_STOPPED'

Expected behavior

PUBREC, PUBREL and PUBCOMP (reason 0), and one record in mqtt-devices with key device/q2.

Actual behavior

Client:

Client q2-179489646331129 sending CONNECT
Client q2-179489646331129 received CONNACK (0)
Client q2-179489646331129 sending PUBLISH (d0, q2, r0, m1, 'device/q2', ... (3 bytes))
Error: The connection was lost.

Zilla:

org.agrona.concurrent.AgentTerminationException: java.util.NoSuchElementException
	at io.aklivity.zilla.runtime.engine/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.doWork(EngineWorker.java:1053)
	...
Caused by: java.util.NoSuchElementException
	at java.base/java.util.LinkedList.removeFirst(LinkedList.java:282)
	at java.base/java.util.LinkedList.remove(LinkedList.java:697)
	at io.aklivity.zilla.runtime.binding.mqtt.kafka/io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.stream.MqttKafkaPublishFactory$KafkaOffsetCommitStream.onKafkaWindow(MqttKafkaPublishFactory.java:2136)
	at io.aklivity.zilla.runtime.binding.mqtt.kafka/io.aklivity.zilla.runtime.binding.mqtt.kafka.internal.stream.MqttKafkaPublishFactory$KafkaOffsetCommitStream.onOffsetCommitMessage(MqttKafkaPublishFactory.java:2062)
	at io.aklivity.zilla.runtime.engine/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.handleReadInitial(EngineWorker.java:1696)
	at io.aklivity.zilla.runtime.engine/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.handleRead(EngineWorker.java:1627)
	at io.aklivity.zilla.runtime.common.agrona/io.aklivity.zilla.runtime.common.agrona.concurrent.ManyToOneRingBuffer.readEx(ManyToOneRingBuffer.java:316)
	at io.aklivity.zilla.runtime.engine/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.doWork(EngineWorker.java:1039)
	... 4 more
engine:events [17/Nov/2026:06:21:04 +0000] [0000000000000000d] ENGINE_STOPPED Engine Stopped.

The crash comes within the same second as the client's BINDING_MQTT_CLIENT_CONNECTED event. Afterwards
mqtt-devices holds one record with key device/q2. With the example's restart: unless-stopped, Zilla restarts, and
the next QoS 2 publish crashes it again.

Notes

Environment

  • Zilla ghcr.io/aklivity/zilla:develop-SNAPSHOT, built locally on 2026-11-17 (image ff8b619b4cd1, arm64), start -e,
    unmodified examples/mqtt.kafka.proxy zilla.yaml
  • Kafka apache/kafka:4.1.1, single node
  • Docker Desktop (Engine 29.8.1) on an Apple Silicon Mac, 10 CPUs and 8 GB for Docker
  • Client: eclipse-mosquitto:2.0 (mosquitto_pub, MQTT 5)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions