Skip to content

mqtt-kafka: QoS 1 PUBACK (reason 0) returned for messages that are not in Kafka after high-rate ingest #3289

Closed

Description

@ankitk-me

Describe the bug

After a burst of high-rate QoS 1 publishing, Zilla returns successful PUBACKs (reason code 0) to new QoS 1 publishers, but their messages are not in Kafka. The client is told the message was accepted, but it can't be found in Kafka 30 s later. There are no errors in the Zilla or Kafka logs.

Reproduced on Zilla 2.7.0 in 2 of 2 runs with the steps below, each on a freshly created stack.

To Reproduce

  1. Start examples/mqtt.kafka.proxy from scratch (docker compose down -v && docker compose up -d). Wait for ENGINE_STARTED.
  2. Run high-rate QoS 1 ingest: 50 publishers, 1 KB payloads, about 5K msg/s for 55 s, then about 25K msg/s for 55 s:
    NET=zilla-mqtt-kafka-proxy_default
    docker run -d --name ingest --network $NET emqx/emqtt-bench:latest pub -h zilla.examples.dev -p 7183 \
      -c 50 -R 500 --prefix "p5k-$(date +%s)-" -t 'device/%i' -q 1 -I 10 -s 1024
    sleep 55; docker rm -f ingest
    docker run -d --name ingest --network $NET emqx/emqtt-bench:latest pub -h zilla.examples.dev -p 7183 \
      -c 50 -R 500 --prefix "p25k-$(date +%s)-" -t 'device/%i' -q 1 -I 2 -s 1024
    sleep 55; docker rm -f ingest
  3. Publish exactly 20,000 QoS 1 messages on new topics (10 clients × 2,000 × 1 KB) and count the PUBACKs with RC 0:
    R="x$(date +%s)"
    docker run --rm --network $NET -e R=$R eclipse-mosquitto:2.0 sh -c '
      PL=$(head -c 1024 /dev/zero | tr "\0" "x")
      for c in $(seq 1 10); do
        ( i=0; while [ $i -lt 2000 ]; do echo "$PL"; i=$((i+1)); done ) |
          mosquitto_pub -d -h zilla.examples.dev -p 7183 -V mqttv5 -i $R-$c -q 1 -t device/$R/$c -l > /tmp/o$c 2>&1 &
      done; wait; cat /tmp/o* | grep -c "received PUBACK.*RC:0"'
  4. Wait 30 s, then count the records in mqtt-devices whose key is one of those topics (the MQTT topic is the Kafka key):
    sleep 30
    docker compose run --rm -T kafkacat kafkacat -b kafka.examples.dev:29092 -C -t mqtt-devices -e -q -f '%k\n' \
      | grep -c "^device/$R/"

Expected behavior

Every PUBACK with RC 0 corresponds to a record in Kafka: the step 4 count equals the step 3 count (20,000). If Zilla can't write to Kafka, it should not send a success PUBACK. It should withhold the PUBACK or return an error reason code.

Actual behavior

Two runs of the steps above, each on a fresh stack:

Run Step 3: PUBACKs with RC 0 Step 4: records with those keys mqtt-devices end offsets over the same period
1 20,000 0 262,450 → 380,670
2 20,000 0 264,838 → 436,382

The offsets kept growing during and after step 3, but every new record carried an ingest topic as its key (device/<n>). None carried a step 3 topic. Zilla stayed running with no restarts and no exceptions. Its log had only ENGINE_STARTED and BINDING_MQTT_CLIENT_CONNECTED events. The Kafka log had no errors or warnings.

In an earlier run of the same sequence, the end offsets didn't move at all during the 20,000 publishes. Another 20 QoS 1 publishes, with a live QoS 1 subscriber, reached neither Kafka nor the subscriber.

Notes

  • Kafka was still receiving the ingest messages more than a minute after those publishers had disconnected. In earlier runs, emqtt-bench sent about 26K msg/s during the 25K phase while Kafka took in about 2K/s. So Zilla seems to acknowledge first and buffer the Kafka writes. The step 3 messages were acknowledged while queued behind that backlog. We haven't checked whether they are written eventually.
  • Because the ingest backlog keeps arriving after the offsets look stable, a check based on offset deltas can't tell these cases apart. Step 4 counts by key for that reason.
  • In each run, 2–5 of the 50 publishers in the 5K phase were rejected at connect with "Session taken over" (mqtt-kafka: concurrent first connects after a fresh Kafka are disconnected with 0x8E (session taken over) #3101). Step 3 had no rejected clients.

Environment

  • Zilla ghcr.io/aklivity/zilla:2.7.0 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
  • Clients: emqx/emqtt-bench:latest, eclipse-mosquitto:2.0 (mosquitto_pub -d, 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