{"record":{"id":"e4231ff5676450e2","repo":"microsoft/garnet","slug":"payload-length-payloadlength-is-larger-than-buff","errorCode":null,"errorMessage":"Payload length {payloadLength} is larger than bufferSize {networkBufferSettings.sendBufferSize} bytes","messagePattern":"Payload length (.+?) is larger than bufferSize (.+?) bytes","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/client/ClientSession/GarnetClientSession.cs","lineNumber":544,"sourceCode":"\n            // 6\n            while (!RespWriteUtils.TryWriteArrayItem(currentAddress, ref curr, end))\n            {\n                Flush();\n                curr = offset;\n            }\n            offset = curr;\n\n            // 7\n            while (!RespWriteUtils.TryWriteArrayItem(nextAddress, ref curr, end))\n            {\n                Flush();\n                curr = offset;\n            }\n            offset = curr;\n\n            if (payloadLength > networkBufferSettings.sendBufferSize)\n                throw new Exception($\"Payload length {payloadLength} is larger than bufferSize {networkBufferSettings.sendBufferSize} bytes\");\n\n            // 8\n            while (!RespWriteUtils.TryWriteBulkString(new Span<byte>((void*)payloadPtr, payloadLength), ref curr, end))\n            {\n                Flush();\n                curr = offset;\n            }\n            offset = curr;\n        }\n\n        /// <summary>\n        /// Throttle the network sender, potentially blocking\n        /// </summary>\n        public void Throttle()\n            => networkSender.Throttle();\n\n        /// <summary>\n        /// Flush current buffer of outgoing messages. Optionally spin-wait for all responses to be received and processed.","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/client/ClientSession/GarnetClientSession.cs#L526-L562","documentation":"In the bulk-payload writer (used by cluster migration / slot transfer commands that embed key addresses plus a value), GarnetClientSession throws when payloadLength exceeds networkBufferSettings.sendBufferSize. The send buffer must be able to hold the entire bulk string in one TryWriteBulkString call (step 8), so a payload larger than the configured send buffer is unrecoverable on the current connection settings. The check fires after the array-item address headers are written but before the value bytes.","triggerScenarios":"Issuing a command that transfers a value whose byte length is greater than the negotiated/configured send buffer size (default sized by NetworkBufferSettings.sendBufferSize); typically cluster slot migration (MIGRATE/SETSLOT) of a large object via the session.","commonSituations":"Migrating large keys/values through GarnetClientSession with a small send buffer; default buffer size lowered for memory savings; transferring blobs larger than the page/buffer budget.","solutions":["Increase networkBufferSettings.sendBufferSize so it exceeds the largest single payload you transfer.","Split or chunk large values so each transfer fits within the configured buffer.","Avoid routing oversized object migrations through the session API; use a bulk path with streaming if available."],"exampleFix":"// before — default buffer too small for large value migration\nvar settings = new NetworkBufferSettings(sendBufferSize: 16 * 1024);\n\n// after — size the send buffer above the maximum single payload\nvar settings = new NetworkBufferSettings(sendBufferSize: 4 * 1024 * 1024);","handlingStrategy":"validation","validationCode":"// Reject payloads larger than the configured send buffer before issuing the command\nif (payloadLength > networkBufferSettings.sendBufferSize)\n    throw new InvalidOperationException(\"payload exceeds send buffer; increase buffer or chunk the value\");","typeGuard":"if (value.Length > maxPayloadForBuffer) { /* chunk or skip */ }","tryCatchPattern":"try { session.SendLargePayload(value); }\ncatch (Exception ex) when (ex.Message.Contains(\"larger than bufferSize\")) { /* resize buffer or chunk */ }","preventionTips":["Size networkBufferSettings.sendBufferSize above your largest single value.","Chunk large values instead of sending them whole.","Validate value size at the application boundary before queuing migrations."],"tags":["csharp","payload-size","network-buffer","cluster-migration","garnet-client-session"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}