grafana/k6 · error

creating temporary directory for downloads

Error message

creating temporary directory for downloads: %w

What it means

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.

Solutions

  1. Set TMPDIR to a writable directory with free space before running k6
  2. Free disk space / inodes on the runner
  3. Raise the open-file limit (ulimit -n) or the container's fd budget
  4. Configure an explicit downloads path option pointing at a writable volume so no temp dir is needed

Example fix

# before: read-only /tmp in container
k6 run script.js # -> creating temporary directory for downloads: ...

# after: writable TMPDIR mounted into the container
docker run -e TMPDIR=/work/tmp -v $PWD/tmp:/work/tmp grafana/k6 run script.js
Defensive patterns

Strategy: validation

Validate before calling

# Validate the temp environment before launching browsers
test -d "${TMPDIR:-/tmp}" && test -w "${TMPDIR:-/tmp}" || { echo 'TMPDIR missing/not writable'; exit 2; }
[ "$(df -Pm "${TMPDIR:-/tmp}" | awk 'NR==2{print $4}')" -gt 100 ] || { echo '<100MB free'; exit 3; }
ulimit -n 4096 || echo 'raise fd limit'
k6 run script.js

Prevention

When it happens

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

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

Related errors


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

Appendix: source

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

	// DownloadsPath is the path where downloads will be stored.
	DownloadsPath string
}

// artifactsDirectory is the prefix for the temporary directory created for downloads.
const artifactsDirectory = "k6browser-artifacts-"

// setDownloadsPath sets the downloads path.
// If the provided path is empty, a temporary directory with
// an artifactsDirectory prefix will be created.
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(

View on GitHub (pinned to 01ffac6f24)