{"record":{"id":"60c0da9ba7a5a98c","repo":"kopia/kopia","slug":"can-t-get-random-bytes-for-temporary-filename","errorCode":null,"errorMessage":"can't get random bytes for temporary filename","messagePattern":"can't get random bytes for temporary filename","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/blob/filesystem/filesystem_storage.go","lineNumber":220,"sourceCode":"\t\t\t\treturn errors.Wrapf(err, \"can't get mod time for file %q\", path)\n\t\t\t}\n\n\t\t\t*t = fi.ModTime()\n\t\t}\n\n\t\treturn nil\n\t}), fs.isRetriable)\n\n\treturn err\n}\n\n// createTempFileWithData creates a temporary file, writes data to it, syncs and closes it.\n// Returns the name of the temporary file and an error.\n// If there is an error writing, syncing, or closing the file, the temporary file is removed.\nfunc (fs *fsImpl) createTempFileWithData(path string, data blob.Bytes) (name string, err error) {\n\trandSuffix := make([]byte, tempFileRandomSuffixLen)\n\tif _, err := rand.Read(randSuffix); err != nil {\n\t\treturn \"\", errors.Wrap(err, \"can't get random bytes for temporary filename\")\n\t}\n\n\ttempFile := fmt.Sprintf(\"%s.tmp.%x\", path, randSuffix)\n\n\tf, err := fs.createTempFileAndDir(tempFile)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"cannot create temporary file\")\n\t}\n\n\tdefer func() {\n\t\tif closeErr := f.Close(); closeErr != nil {\n\t\t\terr = stderrors.Join(err, errors.Wrap(closeErr, \"can't close temporary file\"))\n\t\t}\n\n\t\t// remove temp file when any of the operations fail\n\t\tif err != nil {\n\t\t\tname = \"\"\n","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/repo/blob/filesystem/filesystem_storage.go#L202-L238","documentation":"createTempFileWithData reads random bytes (crypto/rand) to build a unique temporary filename suffix; this error wraps a failure of the system random source. Practically impossible on healthy systems, it indicates the OS entropy source (/dev/urandom, getrandom syscall) is unavailable or returning errors.","triggerScenarios":"crypto/rand.Read failing while generating tempFileRandomSuffixLen bytes for a temp filename during PutBlobInPath/PutBlob.","commonSituations":"Severely degraded or misconfigured containers/OS where getrandom blocks or fails; restricted /dev/urandom in unusual chroot/jail setups.","solutions":["Inspect the wrapped OS error for the random-source failure","Fix the OS entropy source (device nodes, seccomp/apparmor rules)","Restart the host/container if entropy subsystem is wedged","Retry the put once the system random generator works"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var b [8]byte\nif _, err := crypto_rand.Read(b[:]); err != nil {\n    return errors.New(\"system random source unavailable; cannot perform writes\")\n}","typeGuard":null,"tryCatchPattern":"err := st.PutBlob(ctx, blobID, data, blob.PutOptions{})\nif err != nil && strings.Contains(err.Error(), \"random bytes\") {\n    // entropy problem is host-level: back off and retry, alert ops\n    time.Sleep(time.Second)\n    return retryPut()\n}","preventionTips":["Monitor OS entropy health in containers/jails","Fix seccomp/AppArmor rules blocking getrandom","Ensure /dev/urandom exists and is accessible","Alert on crypto/rand errors — they indicate host-level problems"],"tags":["random","filesystem","temp-file"],"backgroundTag":"missing-entropy-source","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}