Skip to content

mqtt-kafka: while ~1,000 QoS 1 or 2 subscribers connect to 16-partition topics, Zilla stops answering every client, with nothing logged #3418

Open

Description

@ankitk-me

Describe the bug

When about 1,000 MQTT clients subscribe at QoS 1 or 2 and the Kafka topics have 16 partitions, Zilla stops
responding a few seconds into the ramp. At that point a few hundred clients have subscribed. Clients still
connecting get no CONNACK, clients that have sent SUBSCRIBE get no SUBACK, and a fresh client connecting
afterwards gets no CONNACK either. The Zilla process keeps running at almost no CPU and logs nothing.

The same clients at QoS 0 all subscribe, and so do QoS 1 clients when the topics have 1 partition.

To Reproduce

  1. Start examples/mqtt.kafka.proxy with ZILLA_VERSION=2.7.2-rc2 and Zilla started with 4 workers, using a
    compose override:
    services:
      zilla:
        command: start -v -e -w 4
    Wait for ENGINE_STARTED.
  2. Give mqtt-devices and mqtt-messages 16 partitions, then restart Zilla:
    for t in mqtt-devices mqtt-messages; do
      docker exec zilla-mqtt-kafka-proxy-kafka-1 /opt/kafka/bin/kafka-topics.sh --bootstrap-server localhost:9092 \
        --alter --topic $t --partitions 16
    done
    docker restart zilla-mqtt-kafka-proxy-zilla-1
  3. Connect 1,000 QoS 1 subscribers, MQTT 3.1.1, one topic each, at 500 connections/s:
    docker run -d --name subs --network zilla-mqtt-kafka-proxy_default emqx/emqtt-bench:0.6.3 sub \
      -h zilla.examples.dev -p 7183 -V 4 -c 1000 -R 500 -t 'device/%i' -q 1 --prefix sub-
  4. After 50 s, look at docker logs subs, then try one more client:
    docker run --rm --network zilla-mqtt-kafka-proxy_default eclipse-mosquitto:2.0 timeout 10 \
      mosquitto_pub -d -h zilla.examples.dev -p 7183 -V mqttv5 -i probe-1 -t device/probe -m hi -q 1

Expected behavior

All 1,000 subscribers get CONNACK and SUBACK, and later clients can connect.

Actual behavior

  • emqtt-bench: subscriptions stopped at 360 after 8 s. 223 clients then failed with ack_timeout.
  • Zilla logged 583 BINDING_MQTT_CLIENT_CONNECTED events, and nothing after them.
  • The extra mosquitto_pub sent CONNECT and got no CONNACK within 10 s.
  • Zilla's CPU fell to almost nothing and stayed there.

A thread dump taken during the stall shows all 4 engine/worker threads parked in
BackoffIdleStrategy.idle, so the workers are alive and have nothing to do. -Xlog:exceptions=info showed no
exception from Zilla code.

The same thing happened in every run with this setup (QoS 1 or 2 subscribers, 16 partitions, 4 workers, about
1,000 subscribers at 500 connections/s). The first four rows used the example's bindings without store on
mqtt-kafka, MQTT 3.1.1 and keep-alive 300 s:

Run Clients connected (Zilla events) Subscribed when it stopped
1,000 QoS 1 subscribers 625 332
1,000 QoS 2 subscribers 538 239
1,000 QoS 2 subscribers, one topic 670 420
1,000 QoS 1 subscribers, one topic 936 498
Steps above (example config) 583 360

Changing one thing at a time, against the same setup:

Change Result
Subscribers at QoS 0 all 1,000 subscribed
Topics with 1 partition all 1,000 subscribed
Only mqtt-devices at 16 partitions, default worker count (10) all 1,000 subscribed
-Xmx5g still stalls
2.7.2-rc1 still stalls

Notes

  • Unread data on one Kafka connection. In every stalled run that was checked, one of Zilla's TCP connections to
    Kafka had 43–77 KB of received data that Zilla never read (/proc/net/tcp receive queue). All the other Kafka
    connections were empty. This was also true with zilla.binding.kafka.client.connection.pool=false.
  • OutOfMemoryError in some runs. In about half the runs, the worker threads also died with
    Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "engine/worker#N".
    The default heap is 1.9 GB here (a quarter of Docker's 7.65 GB). A class histogram near the stall showed about
    48,000 KafkaCacheClientFetchStream instances and 1.69 GB of byte[]; see kafka: every cache client fetch stream allocates a 33 KB heap buffer, so ~1,000 subscribers on 16-partition topics fill a 1.9 GB heap #3419 on the
    per-fetch-stream buffer. With -Xmx5g there was no OutOfMemoryError, but the stall still happened, so memory
    alone doesn't explain it.
  • Two engine crashes seen while narrowing this down, both with non-default settings:
    • With -Dzilla.engine.buffer.slot.capacity=65536, the engine stopped on a Kafka response header that didn't
      fit in the received data. The same crash happens with default settings on AWS, filed as kafka: engine stops with IndexOutOfBoundsException in KafkaClientConnectionPool while reading a Kafka response header #3424:
      java.lang.IndexOutOfBoundsException: limit=22551885 is beyond maxLimit=22551884
        at ...kafka.internal.types.codec.ResponseHeaderFW.wrap(ResponseHeaderFW.java:23)
        at ...kafka.internal.stream.KafkaClientConnectionPool$KafkaClientStream.doStreamData(KafkaClientConnectionPool.java:987)
        at ...kafka.internal.stream.KafkaClientConnectionPool$KafkaClientConnection.onConnectionData(KafkaClientConnectionPool.java:1646)
      
      In KafkaClientConnection.onConnectionData (the no-SASL path), each response's share of a DATA frame is
      Math.min(responseBytes, payload.sizeof()). That's the whole frame length, not what is left after progress.
      A response header is also wrapped without checking that all of it has arrived. Either could misalign response
      boundaries when one frame holds the end of one response and part of the next.
    • With -Dzilla.binding.kafka.client.connection.pool=false, one run stopped with
      NullPointerException: Cannot invoke "ConsumerAssignmentTopicUserdataFW.userdata()" because "consumerAssignmentTopicUserdata" is null.

Environment

  • ghcr.io/aklivity/zilla:2.7.2-rc2 (also 2.7.2-rc1), examples/mqtt.kafka.proxy config, start -v -e -w 4
  • Kafka apache/kafka:4.1.1, single broker, KRaft, mqtt-devices and mqtt-messages with 16 partitions
  • emqx/emqtt-bench:0.6.3, eclipse-mosquitto:2.0, Docker Desktop on Apple Silicon (10 CPUs, 7.65 GB)

Activity

  1. added
    bug
    on Nov 19, 2026
  2. jfallows commented on Nov 19, 2026

    @jfallows
    Contributor

    Reproduced on develop (bad439c0b) with the setup from the description (examples/mqtt.kafka.proxy, 16-partition topics, 4 workers, 1,000 QoS 1 subscribers at 500 connections/s). It stalls in most runs after 100 to 800 subscribers, with one Kafka connection holding 25 to 30 KB of unread data. Cause found; details below.

    Cause: a stream that is aborted while its response is partly received is never acknowledged, so the shared Kafka connection stops reading.

    KafkaClientConnectionPool multiplexes requests from many streams over one connection per cluster and matches responses to requests in order. The connection's receive window only reopens as the stream at the head of the response queue acknowledges the bytes it was given. When a stream is aborted while its response is partly received, the pool keeps receiving the rest of that response and discards it, but never acknowledges those bytes: doStreamAbort has already closed the reply direction, so the later call to doStreamAbort that was meant to acknowledge the response at its end does nothing. The acknowledgement stays at zero, the window (one buffer slot, 32 KB by default) fills with unacknowledged bytes, and the socket is no longer read. Every request queued behind it, from every client sharing the connection, waits for a response that is sitting in the socket. Nothing is logged because nothing fails.

    Evidence from a stalled run (state of the pooled connection and of the stream at the head of its acknowledgement queue):

    • connection: replySeq - replyAck equals replyMax (32768), so no window is left
    • head stream: reply closed and aborting, initial closed, 6,585 response bytes received and discarded, replyAck 0, no response left to receive

    A run with only the response framing from #3424 applied still stalled on its first attempt with exactly this state, so this is a separate defect from #3424. With both changes applied, 6 consecutive runs of the same ramp all reached 1,000 subscribers with no exception and a fully drained connection.

    Two notes on the description:

    • -Dzilla.binding.kafka.client.connection.pool=false has no effect: zilla start reads properties from -P name=value or a properties file, not from JVM system properties, so those runs still used the pool (which fits the one shared connection seen with the pool "off"). With -P zilla.binding.kafka.client.connection.pool=false, 6 consecutive runs reached 1,000 subscribers.
    • I did not reproduce the ConsumerAssignmentTopicUserdataFW.userdata() null case.

    Ruled out: group responses larger than the decode slot (each subscriber has its own single-member group), the 33 KB per fetch stream (#3419) as the cause of the stall (-Xmx5g still stalls), and engine buffer slot exhaustion (the slot is released and the pool is not exhausted).

    Next: spec scripts and a binding IT for an aborted stream with a partly received response on a pooled connection, shown failing on the current base, then the fix in KafkaClientConnectionPool.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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