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
- Validate payload length before calling FromByteArray and skip/log empty messages.
- Ensure gossip and replication channels deliver complete frames (check for partial reads/connection drops).
- 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
- Validate payload length before deserializing.
- Ensure gossip/replication channels deliver complete frames.
- Verify persisted config files are non-empty and intact.
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
- Incompatible ClusterConfig version: expected {ClusterConfigV
- Gossip sample fraction should be in range [0,100]
- Elements collection cannot be empty.
- Sketch size should be power of 2!
- Failed to validate main store metadata at insertion
AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13).
Data as JSON: /api/errors/6b4e91be0bad7ef4.
Report an issue: GitHub.