Skip to content

engine: Zilla fails to start with 32 workers (the default on a 32-vCPU host): "affinity mask must specify at least one bit" #3304

Closed

Description

@ankitk-me

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 (the Tuning.java line 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

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

    @jfallows
    Contributor

    Analysis of #3304.

    Root cause (confirmed). Tuning computes the default mask as (1 << count) - 1 in int arithmetic. Java masks the shift distance to 5 bits, so 32/64/96 workers give mask 0 and EngineWorker.resolveAffinity throws. 33..63 workers give a truncated mask, which silently pins default-affinity bindings to fewer workers. EngineManager has the same int-shift defect in affinity &= ~(1 << bitindex), which clears the wrong bits from bit 31 upward.

    Fix for 1..64 workers. A long mask with count >= Long.SIZE ? -1L : (1L << count) - 1L, plus 1L << in EngineManager. It is on branch fix/3304-engine-default-affinity-mask (commit 2434257). New tests were written first and failed on develop: TuningTest and EngineManagerTest fail at 32 workers (mask 0) and 65 workers (mask 1), and a 32-worker case in EngineAffinityIT fails with the exact error from this issue. After the fix they pass, and ./mvnw verify on runtime/engine passes with checkstyle and jacoco. The unmodified examples/mqtt.kafka.proxy config reaches ENGINE_STARTED with -w 32, -w 33 and -w 64. On unfixed code, -w 32, -w 64 and -w 96 all 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() allocates new Int2ObjectHashMap[64] indexed by the source worker, and the watcher bitmask is a single long. With -w 96 on the fixed code, workers 64 and above crash the receiving worker with ArrayIndexOutOfBoundsException: Index 64 out of bounds for length 64 in EngineWorker.handleReadInitial, and ENGINE_STARTED is not reached. So over 64 workers the engine is neither rejected nor supported. Options:

    1. Fail fast at startup when workers > 64, with a clear message (smallest change, but a 65+ vCPU host then needs -w 64 explicitly).
    2. Make the default workers min(availableProcessors, 64) and also reject an explicit count above 64.
    3. Support more than 64 workers by widening the tuning file layout, the dispatcher and the watcher mask (larger follow-up).

    The branch is pushed, but no PR is open, pending the choice between 1, 2 and 3.


    Generated by Claude Code

  3. added a commit that references this issue on Nov 17, 2026
    dec7284
  4. added a commit that references this issue on Nov 18, 2026
    9b2e38b
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