Repository navigation
Description
Describe the bug
In a 10,000-connection test against a freshly started Zilla 2.7.2-rc1, 26 clients got CONNACK and were then
disconnected by Zilla (TCP closed by the server). All 26 were in the first 5 seconds of the ramp. Every client that
connected after that stayed connected for the full 30 minutes.
Zilla logged BINDING_MQTT_CLIENT_CONNECTED for all 10,000 clients and nothing else: no disconnect event, no error,
no exception.
To Reproduce
Setup (AWS, us-east-1, one subnet and cluster placement group):
- Zilla
ghcr.io/aklivity/zilla:2.7.2-rc1on c6i.8xlarge,start -e -w 31. Config:examples/mqtt.kafka.proxy
bindings with only the stdout log exporter, routingdevice/#tomqtt-devices. - Kafka
apache/kafka:4.1.1, single broker on a separate c6i.8xlarge. Topics:mqtt-devicesandmqtt-messages
(16 partitions),mqtt-retainedandmqtt-sessions(1 partition, compacted). - Two load generators (c6i.2xlarge), each running:
(MQTT 3.1.1, clean session, 100 connections/s in total.)
docker run --network host emqx/emqtt-bench:0.6.3 conn -h <zilla-ip> -p 7183 -V 4 -k 300 -C true \ -c 5000 -R 50 -n <1 | 5001> --prefix <run>-c-
Zilla had been running idle for about 8.5 minutes before the first client connected.
Expected behavior
Every client that gets CONNACK 0 stays connected (keep-alive 300 s, the clients send nothing else).
Actual behavior
| Count | |
|---|---|
Clients that got CONNACK (emqtt-bench connect_succ) |
10,000 |
Zilla BINDING_MQTT_CLIENT_CONNECTED events |
10,000 |
Established TCP connections on the Zilla host (ss, sport 7183), stable for 30 min |
9,974 |
Established TCP connections on the two clients (ss, dport 7183) |
4,981 + 4,993 = 9,974 |
| Client exits | 26 × EXIT for {shutdown,tcp_closed} |
Client exits per second (UTC):
09:13:36 2
09:13:37 5
09:13:38 5
09:13:39 5
09:13:40 7
09:13:41 2
No listen-queue overflows or drops on the Zilla host (TcpExtListenOverflows, TcpExtListenDrops,
TcpExtTCPBacklogDrop all 0). No connect_fail, connection_refused or connection_timeout on the clients.
Notes
- Not reproduced on Docker Desktop: 6 runs of 2,000 connections at 100/s on a fresh stack (10 and 31 workers), 0 drops.
- It looks similar to earlier reports where the first clients on a fresh Zilla were rejected with CONNACK 142 or
disconnected with 131 (mqtt-kafka: concurrent first connects after a fresh Kafka are disconnected with 0x8E (session taken over) #3101, mqtt-kafka: some QoS 1 subscribers get SUBACK but never receive messages when they subscribe before publishing starts; some first get DISCONNECT 131 #3290), but here the client got CONNACK 0 and the reason isn't visible. emqtt-bench
doesn't print a DISCONNECT reason code, if one was sent.
Update: 100,000-connection run
In a later run (fresh Zilla, 100,000 clients connecting at 100/s), Zilla closed 3,134 client connections within one
second (11:05:56), near the end of the ramp and before any client published. All were from the same load generator,
and the clients saw EXIT for {shutdown,tcp_closed}. Zilla again logged nothing besides the connect events. 3,134 is
close to one worker's share of 100,000 clients over 31 workers (about 3,200).
Environment
ghcr.io/aklivity/zilla:2.7.2-rc1(sha256:0dce0a7d...),start -e -w 31(32 workers fails to start: engine: Zilla fails to start with 32 workers (the default on a 32-vCPU host): "affinity mask must specify at least one bit" #3304)- Kafka
apache/kafka:4.1.1, single broker, KRaft - AWS c6i.8xlarge (Zilla, Kafka), c6i.2xlarge × 2 (emqtt-bench 0.6.3), Ubuntu 22.04
Activity
jfallows commentedon Nov 17, 2026
Analysis from a first pass at making this diagnosable. I did not find the cause of (a) or (b), and I have no fix to propose yet.
1. Diagnosability: PR #3313
#3313 adds
BINDING_MQTT_KAFKA_STREAM_FAILED(binding.mqtt.kafka.stream.failed). It is emitted when a failed Kafka stream (session, will signal, meta, describe, offset fetch, offset commit, init producer id, produce, fetch) closes the MQTT session, publish or subscribe stream. It carries the stream kind, the client id, the topic or group, and whether the MQTT reply had already begun. Example from an IT:The Kafka meta stream for topic (mqtt-messages) failed before MQTT client (client-1) was connected, the MQTT stream was closed.If either failure reproduces with that build, the event names the failing Kafka stream. If it does not appear, the close does not come from a Kafka stream failure.
2. What I could reproduce (4 vCPU, 16 GB, Docker, branch image,
start -e -w 31, single Kafka 4.1.1, topics as in the issue)-V 4 -k 300 -C true. Five 2,000 to 5,000 client runs on fresh and idle stacks gave 0 closes and 0 stream-failed events. One of those runs usedclient.max.idle.ms=6000andclient.meta.max.age.msandclient.describe.max.age.msset to 3000, with idle gaps over 20 s.--network host, Zilla stopped accepting after about 850 sessions. Over 3,000 clients exited withtcp_closedand 1,600 witheconnrefused, and the log showed 3 offset-commit stream-failed events at the same second. The same ramp from the compose network connected all 5,000 clients, so I attribute the stall to the host NAT path and do not count it as a Zilla result.-w 4 -P zilla.engine.worker.capacity.limit=64(256 slots in total), 248 and 400 client ramps connected about 218 clients. About 30 and 182 clients were closed by Zilla, mostly withtcp_closedbefore CONNACK and a few withconnect error - closed. Zilla logged nothing. The mechanism is in the code:TcpBindingController.handleAccepttries every worker'sTcpBindingContext.accepted(...), which refuses whenusage.available() <= 0. If none accepts, it callsquietClose(channel), with no event.TcpClientFactory(line 176) rejects an outbound connect on the same condition, so a Kafka connect on a full worker is reset as well.3. Hypotheses checked against the code
KafkaCacheServerMetaFanout(cache.server.reconnectdefaults to 5) reconnects on an upstream end, abort or reset when it still has members. It notifies members only when the reconnect delay is 0. The Kafka client refreshes metadata everymin(client.meta.max.age.ms, client.max.idle.ms / 2), which is 30 s by default, and that does not close members.worker.capacityis a power of two derived from memory. On this host it is 2048 per worker, matching the 131072-bytebudgets*files (131072 / 64). It counts every accepted TCP connection and every outbound connect on that worker, so Kafka connections share the budget. For 31 workers on a 64 GB host I estimate 4096 per worker, about 127k in total, which is above 100k clients. That would not explain closes at about 97k, but the estimate depends on the actual memory and disk of the issue's host.4. Questions and next steps
BINDING_MQTT_KAFKA_STREAM_FAILEDline for the closed clients says which Kafka stream failed and whether CONNACK had been sent.ls -l /var/run/zilla/budgets0, size divided by 64. Please also check how many Kafka connections Zilla holds when the closes start.quietClose. This is a tcp binding change, not mqtt-kafka. I have not implemented it.I am not opening a fix PR for (a) or (b) until the event output or the capacity numbers point at a cause.
Generated by Claude Code
jfallows commentedon Nov 18, 2026
Correction to my earlier analysis: please disregard the request to re-run with the build from #3313. That PR is closed. A Kafka stream reset or abort that closes an MQTT stream is a normal reaction to backend teardown, and Zilla does not log it as an event.
To diagnose this, please capture
zilla dumpwhile the closes happen:zilla dump -w <file>.pcapon the Zilla host before the ramp and keep it running until a minute after the first mass close.-b <namespace.binding,...>limits the capture to specific bindings, for example the mqtt-kafka proxy and the Kafka cache and client bindings.-iinstalls the Wireshark dissector.From that capture we can decide whether a code fix is needed.
Two earlier points still stand:
/var/run/zilla/budgets0divided by 64.Generated by Claude Code
ankitk-me commentedon Nov 19, 2026
Not reproduced on
2.7.2-rc2, on a single Docker Desktop host with Zilla-w 4. In 3 runs of 1,000 QoS 1publishers at 500 connections/s, and 1 run of 10,000 clients at 96/s held for 30 minutes, no client was disconnected
after CONNACK.
ankitk-me commentedon Nov 19, 2026
Reran both cases on AWS with
2.7.2-rc2(sha256:e197b1bb…). The setup is the same as above: c6i.8xlarge broker,start -e -w 31, separate Kafka 4.1.1 host, two c6i.2xlarge load generators, a fresh Zilla left idle for 8.5 minutes before the first client.10,000 clients at 100/s (
emqtt-bench conn), held 10 minutes: not reproduced. All 10,000 connected in 109 s and were still established on the Zilla host at the end. Neither load generator logged an exit, and Zilla logged only the 10,000 connect events.100,000 publishers at 100/s (
emqtt-bench pub, QoS 1, 1 msg/s each): reproduced, and this time Zilla logged something.publish error - tcp_closedandEXIT for {shutdown,tcp_closed}. The other load generator lost none. This was at the end of the ramp, as on rc1 (3,134), and still close to one worker's share (100,000 / 31 ≈ 3,226).So it looks like one produce request rejected by Kafka closes every MQTT client whose publishes go through that Kafka produce stream. Error 87 is INVALID_RECORD.
mqtt-devicesusescleanup.policy=delete, so a missing key isn't the reason; it points to a record batch Kafka considers malformed. Kafka logged nothing at INFO, and Produce v3 responses carry no error message. A rerun with Kafka'skafka.server.ReplicaManagerlogger at DEBUG is in progress to capture Kafka's reason, and I'll add it here.For the earlier local "not reproduced" note above: those runs had at most 10,000 clients, which matches the 10K result here.
ankitk-me commentedon Nov 19, 2026
Follow-up: a second run on a fresh deploy with the same setup reproduced it.
So in both rc2 runs, one INVALID_RECORD produce error on
mqtt-devicescame with about 3,100 clients closed (3,090 and 3,154).Kafka's reason isn't in its log. With
kafka.server.ReplicaManagerat DEBUG, Kafka 4.1.1 logs each produce ("Produce to local log in N ms") but not why a batch was rejected. That reason is only returned in the produce response, asrecord_errorsanderror_message, from Produce v8 onward. Zilla sends Produce v3, which has neither field. Using v8 or later would let theBINDING_KAFKA_PRODUCE_ERRORevent include Kafka's reason.jfallows commentedon Nov 19, 2026
Cause found: the produce client appends records to a record batch whose request has already been encoded, so Kafka receives a batch that disagrees with its own record set. I reproduced both error codes locally and decoded the rejected requests.
Reproduction.
2.7.2-rc2,examples/mqtt.kafka.proxywith-w 4and 16-partitionmqtt-devicesandmqtt-messages, Kafka 4.1.1,emqtt-bench0.6.3 QoS 2 publishers at 1 msg/s (-F 1). With 1,000 publishers, 843 were closed after about 2 minutes; with 3,000, 508 were closed after about 3.5 minutes. Each time Zilla logged one error 2 and one error 87 onmqtt-sessions. I captured the Zilla to Kafka traffic and decoded every Produce request against the record batch format (batch length, record count, last offset delta, record sizes, CRC32C). 165,726 requests were checked and exactly 2 were inconsistent, the 2 that Kafka rejected:Mechanism (
KafkaClientProduceFactory,doEncodeRecordInit). A request carries the first batch in the encode slot, and it can wait there unsent when the network window is short. A record that arrives in that state is still added to the last batch in the slot, and the batch header (length, record count, last offset delta, max timestamp) is updated in place. The request header and the CRC were fixed when the request was encoded, so the broker sees a batch larger than its record set (87). When part of the request has already been sent, the slot is compacted to the left, but the saved position of the open batch is not moved with it. It then points into record data, and if those bytes look like a batch header (the#offsetsrecords onmqtt-sessionscontain runs of-1), the header update overwrites record bytes (2). More publishers on one produce stream make a short network window, and so this state, more likely. This also fits the 100,000-publisher runs: the first requests of a produce stream carry many records at once.Whole-stream effect. One rejected request resets the produce stream, and every MQTT publisher multiplexed on it is closed. That reaction is unchanged. One rejected batch therefore closes every publisher on that stream, which matches the roughly 3,100 closes in one second.
Fix in progress. A batch is open for new records only after the end of the request already encoded from the slot, and its position follows the slot when it is compacted. The test is a spec scenario in which a second record arrives while the first request is encoded but unsent: on the current code the first request carries a 2-record batch header inside a 1-record record set. PR to follow.
Generated by Claude Code
fix(binding-kafka): compute the batch checksum from the position of t…
test(binding-kafka): accept any batch checksum for the 100k random va…
fix(binding-kafka): start a new record batch once the request holding…
fix(binding-kafka): compute the batch checksum from the position of t…
test(binding-kafka): accept any batch checksum for the 100k random va…
fix(binding-kafka): build consistent produce record batches under a s…