microsoft/garnet · error · InvalidDataException

Invalid ClusterConfig payload: too short to contain a versio

Error message

Invalid ClusterConfig payload: too short to contain a version

What it means

ClusterConfig.FromByteArray deserializes a cluster config from a byte payload and first checks that the array has at least one byte (the version byte). A zero-length payload is rejected as InvalidDataException because there is no version to read. This guards against truncated/corrupt gossip or replication messages carrying an empty config body.

Source

Thrown at libs/cluster/Server/ClusterConfigSerializer.cs:134

            //Write segment count at the reserved position
            var _position = ms.Position;
            ms.Position = segmentCountPosition;
            writer.Write(segmentCount);
            ms.Position = _position;
        }

        /// <summary>
        /// Deserialize config from byte array
        /// </summary>
        public static ClusterConfig FromByteArray(byte[] other)
        {
            var ms = new MemoryStream(other);
            var reader = new BinaryReader(ms);

            // Read and validate serialization format version
            if (other.Length < 1)
                throw new InvalidDataException("Invalid ClusterConfig payload: too short to contain a version");
            var version = reader.ReadByte();
            if (version != ClusterConfigVersion)
                throw new InvalidDataException($"Incompatible ClusterConfig version: expected {ClusterConfigVersion}, got {version}");

            var newSlotMap = DeserializeSlotMap(ref reader);

            int numWorkers = reader.ReadInt32();
            var newWorkers = new Worker[numWorkers];
            for (int i = 1; i < numWorkers; i++)
            {
                newWorkers[i].Nodeid = reader.ReadString();
                newWorkers[i].Address = reader.ReadString();
                newWorkers[i].Port = reader.ReadInt32();
                newWorkers[i].ConfigEpoch = reader.ReadInt64();
                newWorkers[i].Role = (NodeRole)reader.ReadByte();

                byte isNull = reader.ReadByte();
                if (isNull > 0)

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Validate payload length before calling FromByteArray and skip/log empty messages.
  2. Ensure gossip and replication channels deliver complete frames (check for partial reads/connection drops).
  3. If loading from disk, verify the config file is non-empty and intact.

Example fix

// before
var config = ClusterConfig.FromByteArray(payload);

// after — guard empty payloads
if (payload is null || payload.Length == 0) { logger?.LogWarning("empty cluster config payload"); return; }
var config = ClusterConfig.FromByteArray(payload);
Defensive patterns

Strategy: validation

Validate before calling

if (payload is null || payload.Length == 0) { logger?.LogWarning("empty cluster config payload"); return; }
var config = ClusterConfig.FromByteArray(payload);

Type guard

bool IsValidConfigPayload(byte[] p) => p is not null && p.Length >= 1;

Try / catch

try { var config = ClusterConfig.FromByteArray(payload); }
catch (InvalidDataException ex) { logger?.LogWarning(ex, "bad cluster config payload"); /* skip/ignore */ }

Prevention

When it happens

Trigger: FromByteArray receives an empty byte[] (length 0) — e.g. a gossip/replication peer sent an empty or truncated config payload, a network read returned no bytes, or a corrupt/stale config was loaded from disk.

Common situations: Cluster nodes exchanging malformed gossip; a replication AOF/config file truncated to zero bytes; a serialization bug producing empty payloads; version skew where a peer sends an unexpected frame.

Related errors


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