microsoft/garnet · error · GarnetException

VectorSetReplayTaskCount should be in range [0,{Environment.

Error message

VectorSetReplayTaskCount should be in range [0,{Environment.ProcessorCount}]!

What it means

Startup validation in the VectorManager constructor: VectorSetReplayTaskCount must be 0 (meaning 'use Environment.ProcessorCount') or a positive value no greater than Environment.ProcessorCount. It sizes both the replicationReplayTasks array and the vectorSetLocks striping, so exceeding the CPU count is rejected. Note the host-layer IntRangeValidation only enforces [0, int.MaxValue], so values above ProcessorCount slip past the CLI validator and fail here at runtime.

Source

Thrown at libs/server/Resp/Vector/VectorManager.cs:197

        {
            this.dbId = dbId;

            IsEnabled = serverOptions.EnableVectorSetPreview;

            // Destination for copying the small graph "stub" records back into memory on disk read (see
            // VectorReadBatch.ReadCopyOptions): the read cache when it is enabled (keeps the writable main log
            // clean), otherwise the main-log tail (still memory-resident, but occupies writable log space).
            StubReadCopyTo = serverOptions.EnableReadCache ? ReadCopyTo.ReadCache : ReadCopyTo.MainLog;

            // Include DB and id so we correlate to what's actually stored in the log
            logger = loggerFactory?.CreateLogger($"{nameof(VectorManager)}:{dbId}");

            replicationBlockEvent = CountingEventSlim.Create();
            // NOTE: for multi-log we need to disable single writer since multiple AOF replay tasks may append to this common channel.
            replicationReplayChannel = Channel.CreateUnbounded<VADDReplicationState>(new() { SingleWriter = !serverOptions.MultiLogEnabled, SingleReader = false, AllowSynchronousContinuations = false });

            if (serverOptions.VectorSetReplayTaskCount < 0 || serverOptions.VectorSetReplayTaskCount > Environment.ProcessorCount)
                throw new GarnetException($"VectorSetReplayTaskCount should be in range [0,{Environment.ProcessorCount}]!");
            var vectorSetReplayCount = serverOptions.VectorSetReplayTaskCount == 0 ? Environment.ProcessorCount : serverOptions.VectorSetReplayTaskCount;
            replicationReplayTasks = new Task[vectorSetReplayCount];
            for (var i = 0; i < replicationReplayTasks.Length; i++)
            {
                replicationReplayTasks[i] = Task.CompletedTask;
            }

            vectorSetLocks = new(vectorSetReplayCount);

            this.getTempSession = getTempSession;
            cleanupTaskChannel = new();
            requestCleanupTaskChannel = new();
            requestDropTaskChannel = new();

            cleanupTask = RunCleanupTaskAsync();
            requestCleanupTask = RunRequestCleanupTaskAsync();
            requestDropTask = RunRequestDropTaskAsync();

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Set --vector-set-replay-task-count to 0 (let it default to the machine's ProcessorCount).
  2. Otherwise set it to a value between 1 and Environment.ProcessorCount for the target machine.
  3. If running under cgroups/containers, confirm what .NET reports as Environment.ProcessorCount and align the value accordingly.
  4. Remove the flag entirely if you do not need to pin it.

Example fix

# before (fails on an 8-core box)
garnet-server --enable-vector-set-preview --vector-set-replay-task-count 32

# after
garnet-server --enable-vector-set-preview --vector-set-replay-task-count 0
Defensive patterns

Strategy: validation

Validate before calling

// Validate before launch
var replayCount = options.VectorSetReplayTaskCount;
if (replayCount < 0 || replayCount > Environment.ProcessorCount) {
    throw new ArgumentOutOfRangeException(nameof(replayCount), $"Must be 0 or in [1, {Environment.ProcessorCount}]");
}

Prevention

When it happens

Trigger: Launching the server with --enable-vector-set-preview and --vector-set-replay-task-count N where N is negative or N > Environment.ProcessorCount. Thrown at VectorManager.cs:196-197 during VectorManager construction (replica replay path).

Common situations: Hardcoding a replay task count from a larger machine into a config deployed on a smaller VM (e.g. 32 set on an 8-core box); cgroup CPU limits where Environment.ProcessorCount is restricted below the configured count; copying a config across environments.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/21eb1923f1cb29bf. Report an issue: GitHub.