{"record":{"id":"a61fe08ee8fc64d9","repo":"grafana/k6","slug":"creating-temporary-directory-for-downloads-w","errorCode":null,"errorMessage":"creating temporary directory for downloads: %w","messagePattern":"creating temporary directory for downloads: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":102,"sourceCode":"\t// DownloadsPath is the path where downloads will be stored.\n\tDownloadsPath string\n}\n\n// artifactsDirectory is the prefix for the temporary directory created for downloads.\nconst artifactsDirectory = \"k6browser-artifacts-\"\n\n// setDownloadsPath sets the downloads path.\n// If the provided path is empty, a temporary directory with\n// an artifactsDirectory prefix will be created.\nfunc (b *BrowserContext) setDownloadsPath(path string) error {\n\tpath = strings.TrimSpace(path)\n\tif path != \"\" {\n\t\tb.DownloadsPath = path\n\t\treturn nil\n\t}\n\tdir, err := os.MkdirTemp(os.TempDir(), artifactsDirectory+\"*\") //nolint:forbidigo\n\tif err != nil {\n\t\treturn fmt.Errorf(\"creating temporary directory for downloads: %w\", err)\n\t}\n\tb.DownloadsPath = dir\n\n\treturn nil\n}\n\n// cleanup cleans up the resources associated with the browser context.\nfunc (b *BrowserContext) cleanup() error {\n\tif err := os.RemoveAll(b.DownloadsPath); err != nil { //nolint:forbidigo\n\t\treturn fmt.Errorf(\"removing downloads path: %w\", err)\n\t}\n\tb.DownloadsPath = \"\"\n\n\treturn nil\n}\n\n// NewBrowserContext creates a new browser context.\nfunc NewBrowserContext(","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L84-L120","documentation":"Every browser context without an explicit downloads path gets one by calling os.MkdirTemp under the OS temp dir (prefix from the artifacts directory setting). This error means that temp-directory creation failed at the OS level. It is an environment problem on the k6 runner, not a browser problem.","triggerScenarios":"TMPDIR (or /tmp) unwritable, missing, read-only, or full; running out of file descriptors (EMFILE) under high concurrency; SELinux/AppArmor denying writes to the temp location.","commonSituations":"Hardened CI containers with a read-only root filesystem and no writable emptyDir; disk-full or inode-full runners; many concurrent browser contexts exhausting fds.","solutions":["Set TMPDIR to a writable directory with free space before running k6","Free disk space / inodes on the runner","Raise the open-file limit (ulimit -n) or the container's fd budget","Configure an explicit downloads path option pointing at a writable volume so no temp dir is needed"],"exampleFix":"# before: read-only /tmp in container\nk6 run script.js # -> creating temporary directory for downloads: ...\n\n# after: writable TMPDIR mounted into the container\ndocker run -e TMPDIR=/work/tmp -v $PWD/tmp:/work/tmp grafana/k6 run script.js","handlingStrategy":"validation","validationCode":"# Validate the temp environment before launching browsers\ntest -d \"${TMPDIR:-/tmp}\" && test -w \"${TMPDIR:-/tmp}\" || { echo 'TMPDIR missing/not writable'; exit 2; }\n[ \"$(df -Pm \"${TMPDIR:-/tmp}\" | awk 'NR==2{print $4}')\" -gt 100 ] || { echo '<100MB free'; exit 3; }\nulimit -n 4096 || echo 'raise fd limit'\nk6 run script.js","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mount a writable temp volume in containers with read-only rootfs","Monitor runner disk space and fd usage","Set an explicit downloads path when temp storage is constrained"],"tags":["temp-dir","filesystem","permissions","disk-full","browser-context"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}