{"record":{"id":"7c0f0dc525d9c3ba","repo":"kubernetes/kops","slug":"writing-header-w","errorCode":null,"errorMessage":"writing header: %w","messagePattern":"writing header: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/otel/otlptracefile/writer.go","lineNumber":140,"sourceCode":"\n\tflags := uint32(0)\n\n\tw.fileMutex.Lock()\n\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}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/otel/otlptracefile/writer.go#L122-L158","documentation":"After passing the closed check, the 16-byte frame header (length, CRC32C checksum, flags, typeCode) is written to the open file. Any Write failure is wrapped as \"writing header: %w\". A partial/garbled trace file may result since the header precedes the body.","triggerScenarios":"Disk full; file descriptor closed externally; I/O error on the underlying filesystem while exporting spans.","commonSituations":"Node running out of disk space during a long test; container with a small tmpfs where the trace file lives; storage device errors.","solutions":["Free disk space or point the trace file at storage with sufficient capacity.","Check host/container storage health and mount state.","Retry the export after fixing I/O; note the trace file may be truncated/corrupt and should be regenerated."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if st, err := os.Stat(filepath.Dir(cfg.Path)); err != nil || !st.IsDir() {\n    return errors.New(\"trace output directory unavailable\")\n}\n// check writable\ntest, _ := os.CreateTemp(filepath.Dir(cfg.Path), \".\")\nif test != nil { test.Close(); os.Remove(test.Name()) }","typeGuard":null,"tryCatchPattern":"if err := w.writeObject(ctx, obj); err != nil {\n    if strings.Contains(err.Error(), \"writing header\") {\n        // treat file as corrupt; close, free disk, recreate writer and retry\n    }\n    return err\n}","preventionTips":["Monitor free disk space where trace files are written","Use durable local storage, not small tmpfs","Rotate or cap trace file size","Alert on filesystem I/O errors"],"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-12T12:17:11.808Z"}