{"record":{"id":"98bf229b047f2153","repo":"hyperledger/fabric","slug":"error-writing-to-temp-file-s","errorCode":null,"errorMessage":"error writing to temp file '%s'","messagePattern":"error writing to temp file '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/persistence.go","lineNumber":61,"sourceCode":"// if the operation crashes midway we're not stuck with a bad package\nfunc (f *FilesystemIO) WriteFile(path, name string, data []byte) error {\n\tif path == \"\" {\n\t\treturn errors.New(\"empty path not allowed\")\n\t}\n\ttmpFile, err := os.CreateTemp(path, \".ccpackage.\")\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error creating temp file in directory '%s'\", path)\n\t}\n\tdefer os.Remove(tmpFile.Name())\n\n\tif n, err := tmpFile.Write(data); err != nil || n != len(data) {\n\t\tif err == nil {\n\t\t\terr = errors.Errorf(\n\t\t\t\t\"failed to write the entire content of the file, expected %d, wrote %d\",\n\t\t\t\tlen(data), n,\n\t\t\t)\n\t\t}\n\t\treturn errors.Wrapf(err, \"error writing to temp file '%s'\", tmpFile.Name())\n\t}\n\n\tif err := tmpFile.Close(); err != nil {\n\t\treturn errors.Wrapf(err, \"error closing temp file '%s'\", tmpFile.Name())\n\t}\n\n\tif err := os.Rename(tmpFile.Name(), filepath.Join(path, name)); err != nil {\n\t\treturn errors.Wrapf(err, \"error renaming temp file '%s'\", tmpFile.Name())\n\t}\n\n\treturn nil\n}\n\n// Remove removes a file from the filesystem - used for rolling back an in-flight\n// Save operation upon a failure\nfunc (f *FilesystemIO) Remove(name string) error {\n\treturn os.Remove(name)\n}","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/persistence.go#L43-L79","documentation":"This is the wrapper message applied to any failure of the temp-file write in WriteFile: it wraps either the raw os error from tmpFile.Write or the short-write error ('failed to write the entire content...') with the temp file's name for diagnostics.","triggerScenarios":"Any error returned by tmpFile.Write(data) — bad file descriptor, I/O error, disk full, or the short-write condition — while saving a chaincode package.","commonSituations":"Storage device errors on the peer's host; container ephemeral storage limits exhausted during `peer lifecycle chaincode install`; concurrent processes interfering with the temp file.","solutions":["Inspect the wrapped cause (Unwrap/`errors.Cause`) to identify the underlying OS error","Free disk space or raise storage limits, then retry the install","Check host/container storage logs (dmesg, docker events) for I/O errors","Ensure only the peer process writes to the install directory"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := ensureDiskSpace(path, uint64(len(data))+1<<20); err != nil { return err }","typeGuard":null,"tryCatchPattern":"err := io.WriteFile(path, name, data)\nfor i := 0; err != nil && i < 2 && isTransientIO(err); i++ {\n    time.Sleep(backoff)\n    err = io.WriteFile(path, name, data)\n}\nif err != nil { return fmt.Errorf(\"saving chaincode package: %w\", err) }","preventionTips":["Monitor host/container storage health (dmesg, SMART) for the peer volume","Avoid shared writes to the chaincode install directory by external processes","Keep headroom on the data volume to absorb large package writes"],"tags":["filesystem","io","wrapping"],"backgroundTag":"disk-full","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}