{"record":{"id":"ee808c80c0b0d911","repo":"microsoft/garnet","slug":"object-serialized-size-currently-at-valueobjectby","errorCode":null,"errorMessage":"Object serialized size currently at {valueObjectBytesWritten} which exceeds max serialization limit of {IHeapObject.MaxSerializedObjectSize}","messagePattern":"Object serialized size currently at (.+?) which exceeds max serialization limit of (.+?)","errorType":"exception","errorClass":"TsavoriteException","httpStatus":null,"severity":"error","filePath":"libs/storage/Tsavorite/cs/src/core/Allocator/ObjectSerialization/ObjectLogWriter.cs","lineNumber":281,"sourceCode":"\n                // If it won't all fit in the remaining buffer, write as much as will.\n                var requestLength = (uint)(data.Length - dataStart);\n                if (requestLength > writeBuffer.RemainingCapacity)\n                    requestLength = (uint)writeBuffer.RemainingCapacity;\n\n                // If it won't all fit in the remaining segment, write as much as will.\n                if ((ulong)requestLength > segmentRemainingLen)\n                    requestLength = (uint)segmentRemainingLen;\n                segmentRemainingLen -= requestLength;\n\n                data.Slice(dataStart, (int)requestLength).CopyTo(writeBuffer.memory.TotalValidSpan.Slice(writeBuffer.currentPosition));\n                dataStart += (int)requestLength;\n                writeBuffer.currentPosition += (int)requestLength;\n                if (inSerialize)\n                {\n                    valueObjectBytesWritten += requestLength;\n                    if (valueObjectBytesWritten >= IHeapObject.MaxSerializedObjectSize)\n                        throw new TsavoriteException($\"Object serialized size currently at {valueObjectBytesWritten} which exceeds max serialization limit of {IHeapObject.MaxSerializedObjectSize}\");\n                }\n\n                // See if we're at the end of the buffer or segment.\n                if (writeBuffer.RemainingCapacity == 0 || segmentRemainingLen == 0)\n                    OnBufferComplete();\n\n                if (segmentRemainingLen == 0)\n                {\n                    flushBuffers.filePosition.AdvanceToNextSegment();\n                    segmentRemainingLen = flushBuffers.filePosition.RemainingSizeInSegment;\n                }\n            }\n        }\n\n        /// <summary>At the end of a buffer, do any processing, flush the current buffer, and move to the next buffer. </summary>\n        /// <remarks>Called during Serialize().</remarks>\n        void OnBufferComplete()\n        {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/storage/Tsavorite/cs/src/core/Allocator/ObjectSerialization/ObjectLogWriter.cs#L263-L299","documentation":"Thrown by ObjectLogWriter during in-place serialization when the running serialized byte count of a value object reaches IHeapObject.MaxSerializedObjectSize (1 << 40 = 1 TiB). This is a hard ceiling to prevent a single object from consuming an unbounded object-log segment; exceeding it means the object being serialized is pathologically large or serialization is in a loop.","triggerScenarios":"Serializing an IHeapObject value whose serialized form is >= 1 TiB, accumulated across the OnSerialize loop in WriteRecordObjects. Triggered when inSerialize is true and valueObjectBytesWritten crosses the limit.","commonSituations":"A user IHeapObject whose Serialize writes far more than expected (e.g. embedding a huge collection or file); a recursive/infinite serialization writing repeated data; a corrupt size field causing an oversized write; legitimately enormous payloads (rare).","solutions":["Reduce the serialized size of the value object — chunk it, stream it, or store the bulk out-of-band and keep a reference.","Audit the IHeapObject.DoSerialize implementation for runaway writes (loops, repeated data).","If genuinely huge data is required, split into multiple records or use the overflow path rather than one serialized object."],"exampleFix":"// before: Serialize writes the entire giant blob\npublic void DoSerialize(BinaryWriter w) => w.Write(_hugeBlob);\n// after: store blob externally and serialize a reference\npublic void DoSerialize(BinaryWriter w) { w.Write(_blobHandle); }","handlingStrategy":"validation","validationCode":"public void DoSerialize(BinaryWriter w)\n{\n    if (_estimatedSerializedSize > MaxBeforeWrite) // your own sane cap, e.g. 1GB\n        throw new InvalidOperationException(\"Refusing to serialize an oversized object; chunk it instead\");\n    /* ... */\n}","typeGuard":null,"tryCatchPattern":"try { valueObject.Serialize(writer); }\ncatch (TsavoriteException ex) when (ex.Message.Contains(\"exceeds max serialization limit\"))\n{\n    logger.LogError(ex, \"Object too large to serialize; split or externalize its data\");\n    throw;\n}","preventionTips":["Audit IHeapObject.DoSerialize implementations for runaway writes.","Chunk very large payloads into multiple records instead of one object.","Enforce an application-level size cap well below 1 TiB."],"tags":["object-log","serialization","size-limit","capacity"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}