{"record":{"id":"4fce444c0ed8c6c1","repo":"kubernetes/kops","slug":"writing-body-w","errorCode":null,"errorMessage":"writing body: %w","messagePattern":"writing body: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/otel/otlptracefile/writer.go","lineNumber":144,"sourceCode":"\tdefer w.fileMutex.Unlock()\n\n\tif w.f == nil {\n\t\treturn fmt.Errorf(\"already closed\")\n\t}\n\n\t// write the object with a header.\n\theader := make([]byte, 16)\n\tbinary.BigEndian.PutUint32(header[0:4], uint32(len(buf)))\n\tbinary.BigEndian.PutUint32(header[4:8], checksum)\n\tbinary.BigEndian.PutUint32(header[8:12], flags)\n\tbinary.BigEndian.PutUint32(header[12:16], uint32(typeCode))\n\n\tif _, err := w.f.Write(header); err != nil {\n\t\treturn fmt.Errorf(\"writing header: %w\", err)\n\t}\n\tif _, err := w.f.Write(buf); err != nil {\n\t\t// TODO: Rotate file?\n\t\treturn fmt.Errorf(\"writing body: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// Close closes the output file.\nfunc (w *writer) Close() error {\n\tw.fileMutex.Lock()\n\tdefer w.fileMutex.Unlock()\n\n\tif w.f != nil {\n\t\tif err := w.f.Close(); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tw.f = nil\n\t}\n\n\treturn nil","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/otel/otlptracefile/writer.go#L126-L162","documentation":"The marshaled body is written immediately after the header; a failing Write is wrapped as \"writing body: %w\". Because the header was already flushed, the output file is left with a header and missing/incomplete body — the code notes a TODO about rotating the file, so recovery is left to the caller.","triggerScenarios":"Same I/O conditions as the header write (disk full, device error) but failing on the body write; disk fills between header and body writes.","commonSituations":"Disk hitting capacity mid-write during heavy span export; flaky network-attached storage.","solutions":["Free disk space and delete the partially written trace file (it is truncated/corrupt).","Re-run the trace export with adequate storage.","If persistent, check storage device/mount health and consider file rotation."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"info, err := os.Stat(cfg.Path)\nif err == nil && info.Size() > maxTraceFileSize {\n    return errors.New(\"trace file full; rotate before exporting\")\n}","typeGuard":null,"tryCatchPattern":"if err := w.writeObject(ctx, obj); err != nil {\n    if strings.Contains(err.Error(), \"writing body\") {\n        // header written but body lost: truncate/recreate the file before retrying\n    }\n    return err\n}","preventionTips":["Reserve headroom on the trace output filesystem","Delete corrupt partial files after a body-write failure","Implement size-based rotation","Alert on disk usage thresholds"],"tags":["opentelemetry","file-io","disk"],"backgroundTag":"disk-full","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}