grafana/k6 · error

error saving summary to '%s' after %d bytes: %w

Error message

error saving summary to '%s' after %d bytes: %w

What it means

After successfully opening a summary output file, k6 streams the rendered summary with io.Copy. If the write fails partway (disk full, quota exceeded, network filesystem drop), the error is wrapped with the number of bytes already written: "error saving summary to '<path>' after N bytes: ...". All such errors are consolidated under 'Could not save some summary information:'.

Source

Thrown at internal/cmd/run.go:596

func handleSummaryResult(fs fsext.Fs, stdOut, stdErr io.Writer, result map[string]io.Reader) error {
	var errs []error

	getWriter := func(path string) (io.Writer, error) {
		switch path {
		case "stdout":
			return stdOut, nil
		case "stderr":
			return stdErr, nil
		default:
			return fs.OpenFile(path, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_TRUNC, 0o666)
		}
	}

	for path, value := range result {
		if writer, err := getWriter(path); err != nil {
			errs = append(errs, fmt.Errorf("could not open '%s': %w", path, err))
		} else if n, err := io.Copy(writer, value); err != nil {
			errs = append(errs, fmt.Errorf("error saving summary to '%s' after %d bytes: %w", path, n, err))
		}
	}

	return consolidateErrorMessage(errs, "Could not save some summary information:")
}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Free disk space or raise the volume/quota, then re-run the test
  2. Write the summary to 'stdout' in handleSummary and let the shell/CI redirect it to a file
  3. Add a pre-run check that the output volume has space (df) and is writable (touch test file)
  4. Reduce summary size by exporting only the metrics you need from data.metrics in handleSummary

Example fix

# before
k6 run --summary-export=/mnt/vol/summary.json script.js
# after
k6 run script.js > run.log 2>&1; k6 run ... | tee summary.json  # summary via stdout, file managed by shell
Defensive patterns

Strategy: validation

Validate before calling

# Guard disk space and writability before long runs
df -hP out | awk 'NR==2 {gsub("%","",$5); if ($5+0 > 90) exit 1}' || { echo 'low disk' >&2; exit 2; }
touch out/.wtest 2>/dev/null && rm -f out/.wtest || { echo 'out/ not writable' >&2; exit 2; }

Prevention

When it happens

Trigger: The disk fills during the summary write at end of test; a container exceeds its writable-layer size limit; an NFS/SMB mount fails mid-write; the file was opened with O_TRUNC on a path that becomes unwritable.

Common situations: Long-running tests on small CI volumes where archives and summaries compete for space; Docker containers with storage size limits; summaries written to mounted volumes with quotas.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/b002d261e55629e4. Report an issue: GitHub.