{"record":{"id":"9865ad8ca7f958f0","repo":"apache/beam","slug":"empty-chunk","errorCode":null,"errorMessage":"empty chunk","messagePattern":"empty chunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/artifact/gcsproxy/staging.go","lineNumber":178,"sourceCode":"// It also computes the SHA256 of the content.\ntype reader struct {\n\tsha256W hash.Hash\n\tbuf     []byte\n\tstream  jobpb.LegacyArtifactStagingService_PutArtifactServer\n}\n\nfunc (r *reader) Read(buf []byte) (int, error) {\n\tif len(r.buf) == 0 {\n\t\t// Buffer empty. Read from upload stream.\n\n\t\tmsg, err := r.stream.Recv()\n\t\tif err != nil {\n\t\t\treturn 0, err // EOF or real error\n\t\t}\n\n\t\tr.buf = msg.GetData().GetData()\n\t\tif len(r.buf) == 0 {\n\t\t\treturn 0, errors.New(\"empty chunk\")\n\t\t}\n\t}\n\n\t// Copy out bytes from non-empty buffer.\n\n\tn := len(r.buf)\n\tif n > len(buf) {\n\t\tn = len(buf)\n\t}\n\tfor i := 0; i < n; i++ {\n\t\tbuf[i] = r.buf[i]\n\t}\n\tif _, err := r.sha256W.Write(r.buf[:n]); err != nil {\n\t\tpanic(err) // cannot fail\n\t}\n\tr.buf = r.buf[n:]\n\treturn n, nil\n}","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/artifact/gcsproxy/staging.go#L160-L196","documentation":"The GCS artifact proxy's staged-artifact reader wraps fetched chunks; if a fetched message carries a zero-length data payload, Read returns errors.New(\"empty chunk\") rather than serving empty bytes, treating an empty chunk as a protocol violation from the server.","triggerScenarios":"Iterating chunks from the artifact staging API during artifact Read when the server (or cache) yields a GetArtifactResponse whose data is empty — e.g. a truncated or mis-encoded artifact in GCS.","commonSituations":"A zero-byte or partially uploaded artifact file in the staging bucket, or a proxy/server bug producing empty messages between real chunks.","solutions":["Verify the staged artifact in GCS is fully uploaded and non-empty; restage the job's artifacts.","Check the serving proxy for logic that emits empty data messages and skip/mask them.","Retry the artifact fetch — transient upload races can yield empty chunks."],"exampleFix":"// before\nif len(r.buf) == 0 {\n\treturn 0, errors.New(\"empty chunk\")\n}\n// after\nif len(r.buf) == 0 {\n\tcontinue // skip empty chunk and fetch next\n}","handlingStrategy":"retry","validationCode":"info, err := gcsObjectInfo(bucket, path)\nif err != nil || info.Size == 0 {\n\treturn fmt.Errorf(\"artifact %s missing or empty; restage\", path)\n}","typeGuard":null,"tryCatchPattern":"n, err := r.Read(buf)\nif err != nil && err.Error() == \"empty chunk\" {\n\t// reopen the artifact reader and retry the fetch\n}","preventionTips":["Verify staged artifacts in GCS are fully uploaded (size > 0) before job submission.","Use atomic GCS uploads to avoid workers reading partially written artifacts.","Retry artifact fetches on transient empty-chunk errors."],"tags":["go","apache-beam","gcs","artifact-staging","io"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}