grafana/k6 · warning

removing downloads path

Error message

removing downloads path: %w

What it means

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.

Solutions

  1. Let downloads finish (or explicitly cancel them) before closing the context/browser
  2. Treat cleanup errors as warnings in teardown instead of failing the run
  3. Fix ownership/permissions of the temp directory used by k6
  4. Periodically clear stale k6 temp dirs on long-lived runners
Defensive patterns

Strategy: try-catch

Try / catch

// Cleanup is best-effort: log removal failures without failing the run
try {
  await browser.close(); // triggers context cleanup incl. downloads dir removal
} catch (e) {
  if (/removing downloads path/.test(String(e))) {
    console.warn('downloads dir cleanup failed; inspect runner temp dir');
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/becdedfaf2e3bfb2. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/browser_context.go:112

func (b *BrowserContext) setDownloadsPath(path string) error {
	path = strings.TrimSpace(path)
	if path != "" {
		b.DownloadsPath = path
		return nil
	}
	dir, err := os.MkdirTemp(os.TempDir(), artifactsDirectory+"*") //nolint:forbidigo
	if err != nil {
		return fmt.Errorf("creating temporary directory for downloads: %w", err)
	}
	b.DownloadsPath = dir

	return nil
}

// cleanup cleans up the resources associated with the browser context.
func (b *BrowserContext) cleanup() error {
	if err := os.RemoveAll(b.DownloadsPath); err != nil { //nolint:forbidigo
		return fmt.Errorf("removing downloads path: %w", err)
	}
	b.DownloadsPath = ""

	return nil
}

// NewBrowserContext creates a new browser context.
func NewBrowserContext(
	ctx context.Context, browser *Browser, id cdp.BrowserContextID, opts *BrowserContextOptions, logger *log.Logger,
) (*BrowserContext, error) {
	// set the default options if none provided.
	if opts == nil {
		opts = DefaultBrowserContextOptions()
	}
	// Always use the [Browser]'s user agent if it's not set by the user.
	// Setting this forces [FrameSession] to set Chromium's user agent.
	if strings.TrimSpace(opts.UserAgent) == "" {
		opts.UserAgent = browser.UserAgent()

View on GitHub (pinned to 01ffac6f24)