{"record":{"id":"becdedfaf2e3bfb2","repo":"grafana/k6","slug":"removing-downloads-path-w","errorCode":null,"errorMessage":"removing downloads path: %w","messagePattern":"removing downloads path: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":112,"sourceCode":"func (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(\n\tctx context.Context, browser *Browser, id cdp.BrowserContextID, opts *BrowserContextOptions, logger *log.Logger,\n) (*BrowserContext, error) {\n\t// set the default options if none provided.\n\tif opts == nil {\n\t\topts = DefaultBrowserContextOptions()\n\t}\n\t// Always use the [Browser]'s user agent if it's not set by the user.\n\t// Setting this forces [FrameSession] to set Chromium's user agent.\n\tif strings.TrimSpace(opts.UserAgent) == \"\" {\n\t\topts.UserAgent = browser.UserAgent()","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L94-L130","documentation":"During browser-context cleanup, k6 deletes the context's downloads directory with os.RemoveAll. This error wraps a removal failure. It occurs in cleanup paths, so it typically signals a race with an in-flight download or a filesystem permission/mount issue rather than a test-logic problem.","triggerScenarios":"A download still writing files when the context cleans up; the temp dir's permissions or ownership changed mid-run; a read-only or NFS-mounted temp path; double cleanup where the path was already removed.","commonSituations":"Tests that trigger downloads and close the browser before the file finishes; containers where the temp volume becomes read-only; runners accumulating locked temp files.","solutions":["Let downloads finish (or explicitly cancel them) before closing the context/browser","Treat cleanup errors as warnings in teardown instead of failing the run","Fix ownership/permissions of the temp directory used by k6","Periodically clear stale k6 temp dirs on long-lived runners"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Cleanup is best-effort: log removal failures without failing the run\ntry {\n  await browser.close(); // triggers context cleanup incl. downloads dir removal\n} catch (e) {\n  if (/removing downloads path/.test(String(e))) {\n    console.warn('downloads dir cleanup failed; inspect runner temp dir');\n  } else throw e;\n}","preventionTips":["Finish or cancel downloads before closing the browser","Schedule cleanup of stale k6 temp dirs on long-lived runners","Verify temp-dir ownership matches the k6 process user"],"tags":["cleanup","filesystem","downloads","permissions","browser-context"],"backgroundTag":"file-cleanup-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"}