{"record":{"id":"8406fa7c83a48f07","repo":"microsoft/garnet","slug":"invalid-metadata-length-hlri-cookie-length-12","errorCode":null,"errorMessage":"invalid metadata length: {hlri.cookie.Length} < 12","messagePattern":"invalid metadata length: (.+?) < 12","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"libs/cluster/Server/Replication/GarnetClusterCheckpointManager.cs","lineNumber":125,"sourceCode":"        /// <param name=\"recoveredReplicationId\"></param>\n        /// <exception cref=\"Exception\"></exception>\n        public unsafe void GetCheckpointCookieMetadata(Guid logToken, ref AofAddress recoveredSafeAofAddress, out string recoveredReplicationId)\n        {\n            var metadata = GetLogCheckpointMetadata(logToken);\n            var hlri = ConvertMetadata(metadata);\n\n            recoveredReplicationId = null;\n            if (RecoveredSafeAofAddress.Length == 1)\n            {\n                // Legacy single log deserialization for backward compatibility\n                var bytesRead = sizeof(int);\n                fixed (byte* ptr = hlri.cookie)\n                {\n                    if (hlri.cookie.Length < 4) throw new Exception($\"invalid metadata length: {hlri.cookie.Length} < 4\");\n                    var cookieSize = *(int*)ptr;\n                    bytesRead += cookieSize;\n\n                    if (hlri.cookie.Length < 12) throw new Exception($\"invalid metadata length: {hlri.cookie.Length} < 12\");\n                    recoveredSafeAofAddress[0] = *(long*)(ptr + 4);\n\n                    if (hlri.cookie.Length < 52) throw new Exception($\"invalid metadata length: {hlri.cookie.Length} < 52\");\n                    recoveredReplicationId = Encoding.ASCII.GetString(ptr + 12, 40);\n                }\n            }\n            else\n            {\n                // Multi-log cookie\n                using var ms = new MemoryStream(hlri.cookie);\n                using var reader = new BinaryReader(ms, Encoding.ASCII);\n                recoveredReplicationId = reader.ReadInt32() > 0 ? reader.ReadString() : null;\n                recoveredSafeAofAddress = AofAddress.Deserialize(reader);\n                reader.Dispose();\n                ms.Dispose();\n            }\n        }\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/cluster/Server/Replication/GarnetClusterCheckpointManager.cs#L107-L143","documentation":"Thrown during legacy single-log cookie deserialization when the cookie is at least 4 bytes but fewer than 12, too small to read the 8-byte recoveredSafeAofAddress long that follows the 4-byte size prefix. Like error 29 it signals a corrupt or version-mismatched checkpoint metadata blob, just one that passed the first length check.","triggerScenarios":"GetCheckpointCookieMetadata on a cookie between 4 and 11 bytes long — a malformed or truncated checkpoint produced by an incompatible/crashed write.","commonSituations":"Same family as error 29: cross-version checkpoint incompatibility, truncated checkpoint after a crash, or on-disk metadata corruption.","solutions":["Discard the affected checkpoint and recover from a valid full checkpoint.","Confirm the checkpoint was produced by a compatible Garnet version.","Re-run a full checkpoint after any version upgrade to rewrite cookies in the current format."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate cookie length for the safeAofAddress read\nif (hlri.cookie == null || hlri.cookie.Length < 12)\n    throw new InvalidDataException($\"Checkpoint cookie too short ({hlri?.cookie?.Length ?? -1} bytes) for AOF address; corrupt or incompatible checkpoint\");","typeGuard":null,"tryCatchPattern":"try { manager.GetCheckpointCookieMetadata(logToken, ref addr, out var id); }\ncatch (Exception ex) when (ex.Message.Contains(\"invalid metadata length\"))\n{\n    logger?.LogError(ex, \"Corrupt/incompatible checkpoint cookie for log {logToken}\", logToken);\n    // recover from a valid full checkpoint\n}","preventionTips":["Treat any 'invalid metadata length' error as a corrupt/incompatible checkpoint.","Maintain compatible-version full checkpoints for fallback.","Rewrite checkpoints after upgrades that alter the cookie layout."],"tags":["cluster","replication","checkpoint","serialization","data-integrity","garnet"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}