{"record":{"id":"f06bc1e0dcdf7666","repo":"argoproj/argo-workflows","slug":"failed-to-create-temp-file-w","errorCode":null,"errorMessage":"failed to create temp file: %w","messagePattern":"failed to create temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"workflow/artifacts/common/streaming.go","lineNumber":33,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tdefer cleanup()\n\treturn save(path)\n}\n\n// BufferReaderToTempFile buffers reader into a new temp file (named per the os.CreateTemp\n// pattern, e.g. \"s3-upload-*\") so its content can be re-read multiple times, which most\n// storage SDKs require for retry/backoff. It returns the temp file's path and a cleanup\n// function that removes it; cleanup is safe to call more than once. On error, any partially\n// written temp file is removed before returning, so callers only need to defer cleanup\n// after a nil error.\nfunc BufferReaderToTempFile(reader io.Reader, pattern string) (path string, cleanup func(), err error) {\n\tnoop := func() {}\n\n\ttmpFile, err := os.CreateTemp(\"\", pattern)\n\tif err != nil {\n\t\treturn \"\", noop, fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\tname := tmpFile.Name()\n\tcleanup = func() {\n\t\t_ = os.Remove(name)\n\t}\n\n\tif _, err := io.Copy(tmpFile, reader); err != nil {\n\t\t_ = tmpFile.Close()\n\t\tcleanup()\n\t\treturn \"\", noop, fmt.Errorf(\"failed to buffer stream to temp file: %w\", err)\n\t}\n\tif err := tmpFile.Close(); err != nil {\n\t\tcleanup()\n\t\treturn \"\", noop, fmt.Errorf(\"failed to close temp file: %w\", err)\n\t}\n\n\treturn name, cleanup, nil\n}","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/argoproj/argo-workflows/blob/35bff19146f5a6ada77468c431f2624bd577e373/workflow/artifacts/common/streaming.go#L15-L51","documentation":"BufferReaderToTempFile creates a temp file with os.CreateTemp to buffer an artifact stream before saving. This error wraps the os.CreateTemp failure, meaning the process could not create a file in the system temp dir (os.TempDir, typically /tmp).","triggerScenarios":"os.CreateTemp returns an error: temp filesystem full (ENOSPC), no read-write /tmp in the container, permission denied on the temp dir, or too many open file descriptors (EMFILE/ENFILE).","commonSituations":"Pods with a tiny read-only emptyDir at /tmp; node disk pressure; containers run with read-only root filesystem and no tmpfs mount; ulimit -n exhaustion from leaked fds in a long-running controller.","solutions":["Free space on the temp filesystem (df -h /tmp) or expand the node/pod disk.","Mount a writable tmpfs/emptyDir at /tmp or set TMPDIR to a writable volume.","If read-only rootfs, add an emptyDir volume and mount it at /tmp (or set TMPDIR to a mounted path).","Check open-file limits (lsof count, ulimit) for fd leaks; restart the leaking process.","Set the TMPDIR env var to a larger persistent volume if streams are very large."],"exampleFix":"# before: read-only container, no tmp\nspec:\n  containers: [ ... ]\n# after\nspec:\n  containers:\n  - name: main\n    volumeMounts: [{name: tmp, mountPath: /tmp}]\n  volumes:\n  - name: tmp\n    emptyDir: {}","handlingStrategy":"validation","validationCode":"// verify the temp dir is writable and has space before streaming\nif info, err := os.Stat(os.TempDir()); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"temp dir %s unusable\", os.TempDir())\n}\nif err := unix.Access(os.TempDir(), unix.W_OK); err != nil {\n    return fmt.Errorf(\"temp dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := artifactscommon.SaveStreamViaTempFile(reader, \"upload-*\", save); err != nil {\n    if strings.Contains(err.Error(), \"failed to create temp file\") && errors.Is(err, syscall.ENOSPC) {\n        return fmt.Errorf(\"disk full on temp volume — expand /tmp or set TMPDIR\")\n    }\n    return err\n}","preventionTips":["Mount a writable emptyDir/tmpfs at /tmp (or set TMPDIR) in executor pods.","Monitor temp-volume disk usage and set alerts below capacity.","Avoid read-only root filesystems without a tmp mount.","Check open-fd limits; os.CreateTemp also fails on EMFILE."],"tags":["filesystem","temp-file","disk-full","io"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"35bff19146f5a6ada77468c431f2624bd577e373","analyzedAt":"2026-09-03T19:34:35.908Z","contentChangedAt":"2026-09-03T19:34:35.908Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}