Repository navigation
Description
Describe the bug
With exactly 32 engine workers, Zilla exits at start-up with IllegalStateException: affinity mask must specify at least one bit. 32 workers is the default on any 32-vCPU machine (for example AWS c6i.8xlarge), so Zilla doesn't start
there at all unless -w is set. 64 and 96 workers fail the same way. 16, 31 and 33 start.
To Reproduce
With the unmodified examples/mqtt.kafka.proxy/etc/zilla.yaml (Kafka doesn't need to be reachable):
docker run --rm -v "$PWD/etc:/etc/zilla:ro" -e KAFKA_BOOTSTRAP_SERVER=localhost:9092 \
ghcr.io/aklivity/zilla:2.7.2-rc1 start -e -w 32-w |
Result |
|---|---|
| 16, 31, 33 | ENGINE_STARTED |
| 32, 64, 96 | exits with code 1 |
On a 32-vCPU AWS c6i.8xlarge, start -e without -w fails the same way.
Expected behavior
Zilla starts with any supported worker count, including the default on a 32-vCPU host.
Actual behavior
java.util.concurrent.CompletionException: java.lang.IllegalStateException: affinity mask must specify at least one bit: zilla-mqtt-kafka-proxy.north_kafka_cache_client 0
...
Caused by: java.lang.IllegalStateException: affinity mask must specify at least one bit: zilla-mqtt-kafka-proxy.north_kafka_cache_client 0
at [email protected]/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.resolveAffinity(EngineWorker.java:2391)
at [email protected]/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.supplyAffinity(EngineWorker.java:2377)
at [email protected]/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.resolveRemoteIndex(EngineWorker.java:2345)
at [email protected]/io.aklivity.zilla.runtime.engine.internal.registry.EngineWorker.supplyInitialId(EngineWorker.java:566)
at [email protected]/io.aklivity.zilla.runtime.binding.kafka.internal.stream.KafkaCacheServerAddressFactory$KafkaAddressStream.<init>(KafkaCacheServerAddressFactory.java:139)
...
On the AWS host the binding named was south_kafka_cache_server; locally it was north_kafka_cache_client.
Cause
runtime/engine/src/main/java/io/aklivity/zilla/runtime/engine/internal/Tuning.java builds the default affinity
mask in an int:
private final int available;
...
this.available = (1 << count) - 1;Java masks an int shift distance to 5 bits, so 1 << 32 == 1 and the mask is 0 for 32 workers (also 64, 96).
Tuning.affinity() returns that mask for every binding without an explicit affinity, and
EngineWorker.resolveAffinity() rejects it.
From the same code, 33 to 63 workers start but get a mask of (1 << (count - 32)) - 1. With 33 workers that is
0b1, which would put every binding on worker 0. We haven't measured this.
A possible fix is a long field and mask, for example count >= Long.SIZE ? -1L : (1L << count) - 1.
#1338 reported the same error on a Windows 11 workstation and was closed as an environment problem ("works on another
machine"). It may have been this bug, if that workstation had 32 or 64 logical processors.
Environment
ghcr.io/aklivity/zilla:2.7.2-rc1(theTuning.javaline dates back to the original engine code)- AWS c6i.8xlarge (32 vCPU), Ubuntu 22.04, Docker 24; also reproduced on Docker Desktop (Apple Silicon) with
-w 32
Activity
jfallows commentedon Nov 17, 2026
Analysis of #3304.
Root cause (confirmed).
Tuningcomputes the default mask as(1 << count) - 1inintarithmetic. Java masks the shift distance to 5 bits, so 32/64/96 workers give mask 0 andEngineWorker.resolveAffinitythrows. 33..63 workers give a truncated mask, which silently pins default-affinity bindings to fewer workers.EngineManagerhas the same int-shift defect inaffinity &= ~(1 << bitindex), which clears the wrong bits from bit 31 upward.Fix for 1..64 workers. A
longmask withcount >= Long.SIZE ? -1L : (1L << count) - 1L, plus1L <<inEngineManager. It is on branchfix/3304-engine-default-affinity-mask(commit 2434257). New tests were written first and failed ondevelop:TuningTestandEngineManagerTestfail at 32 workers (mask 0) and 65 workers (mask 1), and a 32-worker case inEngineAffinityITfails with the exact error from this issue. After the fix they pass, and./mvnw verifyonruntime/enginepasses with checkstyle and jacoco. The unmodifiedexamples/mqtt.kafka.proxyconfig reachesENGINE_STARTEDwith-w 32,-w 33and-w 64. On unfixed code,-w 32,-w 64and-w 96all fail with this issue's error.Open decision: more than 64 workers. Widening the mask alone would not make this work, because the engine has a second 64-worker limit.
EngineWorker.initDispatcher()allocatesnew Int2ObjectHashMap[64]indexed by the source worker, and the watcher bitmask is a single long. With-w 96on the fixed code, workers 64 and above crash the receiving worker withArrayIndexOutOfBoundsException: Index 64 out of bounds for length 64inEngineWorker.handleReadInitial, andENGINE_STARTEDis not reached. So over 64 workers the engine is neither rejected nor supported. Options:workers > 64, with a clear message (smallest change, but a 65+ vCPU host then needs-w 64explicitly).workersmin(availableProcessors, 64)and also reject an explicit count above 64.The branch is pushed, but no PR is open, pending the choice between 1, 2 and 3.
Generated by Claude Code
fix(engine): use long arithmetic for default and limited affinity masks
fix(engine): use long affinity masks and limit workers to 64 (aklivit…