{"record":{"id":"981f33d00c75ecb7","repo":"apache/beam","slug":"chunk-write-failed","errorCode":null,"errorMessage":"chunk write failed","messagePattern":"chunk write failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/artifact/materialize.go","lineNumber":282,"sourceCode":"\n\treturn nil\n}\n\nfunc writeChunks(stream jobpb.ArtifactRetrievalService_GetArtifactClient, w io.Writer) (string, error) {\n\tsha256W := sha256.New()\n\tfor {\n\t\tchunk, err := stream.Recv()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tif _, err := sha256W.Write(chunk.Data); err != nil {\n\t\t\tpanic(err) // cannot fail\n\t\t}\n\t\tif _, err := w.Write(chunk.Data); err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"chunk write failed\")\n\t\t}\n\t}\n\treturn hex.EncodeToString(sha256W.Sum(nil)), nil\n}\n\nfunc legacyMaterialize(ctx context.Context, endpoint string, rt string, dest string) ([]*pipepb.ArtifactInformation, error) {\n\tcc, err := grpcx.Dial(ctx, endpoint, 2*time.Minute)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer cc.Close()\n\n\tclient := jobpb.NewLegacyArtifactRetrievalServiceClient(cc)\n\n\tm, err := client.GetManifest(ctx, &jobpb.GetManifestRequest{RetrievalToken: rt})\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to get manifest\")\n\t}","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/artifact/materialize.go#L264-L300","documentation":"Wrapped error from writeChunks when writing a received chunk into the buffered file writer fails during artifact streaming. The SHA256 hasher cannot fail (panics defensively), so this always reflects a real write error to the buffered writer's underlying destination later surfaced at flush, or memory/buffer issues. retrieval then wraps it with \"failed to retrieve chunk for <file>\".","triggerScenarios":"During Materialize/Retrieve, bufio.Writer.Write returns an error while copying chunk.Data from the gRPC GetArtifact stream — almost always a previously failed underlying write being reported by bufio's sticky error.","commonSituations":"Disk full or I/O failure on the worker while streaming a large artifact; the target file descriptor became invalid (e.g. storage unmounted); extremely rare memory pressure.","solutions":["Verify free disk space and volume health where dest resides; fix underlying storage errors first.","Rerun the pipeline after freeing space — MultiRetrieve retries transient failures.","Point dest to a different, healthy local filesystem.","If it persists, capture the wrapped cause (printed via errors.Wrapf chain) for storage-layer diagnostics."],"exampleFix":"// before: full disk volume\nartifact.Materialize(ctx, endpoint, deps, rt, \"/mnt/nearly-full\")\n// after: clean space or choose healthy volume\nexec.Command(\"df\", \"-h\", dest).Run() // verify headroom first\nartifact.Materialize(ctx, endpoint, deps, rt, dest)","handlingStrategy":"try-catch","validationCode":"// Ensure destination has headroom and is writable before streaming:\nprobe := filepath.Join(dest, \".writeprobe\")\nif err := os.WriteFile(probe, make([]byte, 1<<20), 0o644); err != nil {\n\treturn fmt.Errorf(\"dest cannot absorb writes: %w\", err)\n}\nos.Remove(probe)","typeGuard":null,"tryCatchPattern":"if err := artifact.Materialize(ctx, endpoint, deps, rt, dest); err != nil {\n\tif strings.Contains(err.Error(), \"chunk write failed\") {\n\t\tlog.Printf(\"buffered write failure while streaming artifact; check disk/storage: %v\", err)\n\t\t// surface the wrapped cause to operators\n\t}\n\treturn err\n}","preventionTips":["Guarantee free disk space exceeds total artifact size before retrieval.","Avoid unmounting/replacing volumes while jobs are retrieving artifacts.","Use local SSD or reliable volumes for dest.","Watch for bufio sticky errors indicating earlier write failures."],"tags":["go","io","filesystem","streaming","beam-artifacts"],"backgroundTag":"file-write-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}