{"record":{"id":"fd75a7717f6afd7e","repo":"hyperledger/fabric","slug":"error-while-creating-temp-dir-s","errorCode":null,"errorMessage":"error while creating temp dir [%s]","messagePattern":"error while creating temp dir \\[(.+?)\\]","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/snapshot.go","lineNumber":105,"sourceCode":"\t\tsnapshotAdditionalMetadata: additionalMetadata,\n\t}, nil\n}\n\n// generateSnapshot generates a snapshot. This function should be invoked when commit on the kvledger are paused\n// after committing the last block fully and further the commits should not be resumed till this function finishes\nfunc (l *kvLedger) generateSnapshot() error {\n\tsnapshotsRootDir := l.config.SnapshotsConfig.RootDir\n\tbcInfo, err := l.GetBlockchainInfo()\n\tif err != nil {\n\t\treturn err\n\t}\n\tlastBlockNum := bcInfo.Height - 1\n\tsnapshotTempDir, err := os.MkdirTemp(\n\t\tSnapshotsTempDirPath(snapshotsRootDir),\n\t\tfmt.Sprintf(\"%s-%d-\", l.ledgerID, lastBlockNum),\n\t)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error while creating temp dir [%s]\", snapshotTempDir)\n\t}\n\tdefer os.RemoveAll(snapshotTempDir)\n\n\tnewHashFunc := func() (hash.Hash, error) {\n\t\treturn l.hashProvider.GetHash(snapshotHashOpts)\n\t}\n\n\ttxIDsExportSummary, err := l.blockStore.ExportTxIds(snapshotTempDir, newHashFunc)\n\tif err != nil {\n\t\treturn err\n\t}\n\tlogger.Debugw(\"Exported TxIDs from blockstore\", \"channelID\", l.ledgerID)\n\n\tconfigsHistoryExportSummary, err := l.configHistoryRetriever.ExportConfigHistory(snapshotTempDir, newHashFunc)\n\tif err != nil {\n\t\treturn err\n\t}\n\tlogger.Debugw(\"Exported collection config history\", \"channelID\", l.ledgerID)","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/snapshot.go#L87-L123","documentation":"generateSnapshot creates a temporary directory under <snapshotsRootDir>/temp to stage snapshot files before finalizing. This error wraps an os.MkdirTemp failure, meaning the OS refused to create the staging directory (permissions, missing parent, disk full, etc.).","triggerScenarios":"Calling ledger.GenerateSnapshot() when the snapshots root's temp directory cannot be created: wrong permissions, root dir deleted while node running, invalid path, or no inodes/space.","commonSituations":"snapshots.rootDir misconfigured in core.yaml to a read-only or non-existent volume; container running as non-root without write access to mounted volume; disk-full conditions on Kubernetes PVCs.","solutions":["Check snapshots.rootDir exists and is writable by the peer process user (ls -ld, touch a file inside it)","Fix volume mount permissions/ownership in the container or host","Free disk space / inodes on the snapshots volume","Correct the core.yaml snapshots.rootDir path if it points to an invalid location"],"exampleFix":"// before\nsnapshots:\n  rootDir: /var/snapshots   # read-only mount\n// after\nsnapshots:\n  rootDir: /var/hyperledger/production/snapshots  # writable volume; chown peer:peer","handlingStrategy":"try-catch","validationCode":"const dir = \"/var/hyperledger/production/snapshots\"\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() { return errors.New(\"snapshots rootDir missing or not a directory\") }\nprobe := filepath.Join(dir, \".write-test\")\nif err := os.WriteFile(probe, nil, 0o600); err != nil { return errors.New(\"snapshots rootDir not writable\") }\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"err := ledger.GenerateSnapshot()\nvar pe *fs.PathError\nif err != nil && errors.As(err, &pe) {\n    log.Errorf(\"snapshot temp dir creation failed (%s): check permissions/space on %s\", pe.Op, pe.Path)\n}","preventionTips":["Pre-create the snapshots rootDir with correct ownership before starting the peer","Monitor disk space and inodes on the snapshots volume","Run the peer as a user with write access to mounted volumes","Validate core.yaml snapshots.rootDir in deployment checks"],"tags":["filesystem","permissions","disk","snapshot"],"backgroundTag":"mkdir-permission-denied","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"}