apache/beam · error

failed to flush chunks for

Error message

failed to flush chunks for %v

What it means

Wraps a failure of bufio.Writer.Flush in artifact.retrieve, meaning buffered artifact data could not be pushed to the file descriptor (typically a disk write error). The file is closed and the partial artifact discarded. The filename is included in the message.

Solutions

  1. Free disk space or enlarge the volume backing dest, then rerun.
  2. Point dest at local, reliably writable storage instead of a constrained ephemeral mount.
  3. Check container/storage quotas for the worker (e.g. Kubernetes emptyDir sizeLimit).
  4. Investigate storage subsystem health (dmesg/logs) if errors persist across nodes.

Example fix

// before: tiny ephemeral volume as dest
artifact.Materialize(ctx, endpoint, deps, rt, "/tmp")
// after: dedicated persistent volume with adequate space
artifact.Materialize(ctx, endpoint, deps, rt, "/var/beam/artifacts")
Defensive patterns

Strategy: validation

Validate before calling

// Verify writable space on dest before retrieval:
var st syscall.Statfs_t
if err := syscall.Statfs(dest, &st); err == nil {
	avail := int64(st.Bavail) * int64(st.Bsize)
	if avail < 512<<20 {
		return fmt.Errorf("insufficient space in %s: %d bytes", dest, avail)
	}
}

Try / catch

if err := artifact.Materialize(ctx, endpoint, deps, rt, dest); err != nil {
	if strings.Contains(err.Error(), "failed to flush chunks") {
		return fmt.Errorf("storage write failure at %s: %w", dest, err)
	}
	return err
}

Prevention

When it happens

Trigger: Materialize/Retrieve downloading an artifact where Flush fails: disk full, I/O error, quota exceeded, or the underlying file descriptor became invalid during the download.

Common situations: Worker node running out of disk space mid-download; NFS/EFS volume hiccups; container ephemeral storage quota exceeded; failing disk hardware.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/0a7003065b19c468. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/artifact/materialize.go:248

	stream, err := a.client.GetArtifact(ctx, &jobpb.GetArtifactRequest{Artifact: a.dep})
	if err != nil {
		return err
	}

	fd, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0755)
	if err != nil {
		return err
	}
	w := bufio.NewWriter(fd)

	sha256Hash, err := writeChunks(stream, w)
	if err != nil {
		fd.Close() // drop any buffered content
		return errors.Wrapf(err, "failed to retrieve chunk for %v", filename)
	}
	if err := w.Flush(); err != nil {
		fd.Close()
		return errors.Wrapf(err, "failed to flush chunks for %v", filename)
	}
	stat, _ := fd.Stat()
	log.Printf("Downloaded: %v (sha256: %v, size: %v)", filename, sha256Hash, stat.Size())

	if err := fd.Close(); err != nil {
		return err
	}

	if isArtifactValidationEnabled(ctx) {
		if a.expectedSha256 == "" {
			log.Printf("WARN: Artifact validation skipped for file: %v", filename)
		} else if sha256Hash != a.expectedSha256 {
			return errors.Errorf("bad SHA256 for %v: %v, want %v", filename, sha256Hash, a.expectedSha256)
		}
	}

	return nil
}

View on GitHub (pinned to 12126d8942)