{"record":{"id":"061f692f57495b3b","repo":"apache/beam","slug":"error-decoding-buckets-w","errorCode":null,"errorMessage":"error decoding buckets: %w","messagePattern":"error decoding buckets: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/id_range_split.go","lineNumber":125,"sourceCode":"\t\tbson.D{{\n\t\t\tKey: \"$bucketAuto\",\n\t\t\tValue: bson.M{\n\t\t\t\t\"groupBy\": \"$_id\",\n\t\t\t\t\"buckets\": count,\n\t\t\t},\n\t\t}},\n\t}\n\n\topts := options.Aggregate().SetAllowDiskUse(true)\n\n\tcursor, err := collection.Aggregate(ctx, pipeline, opts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error executing bucketAuto aggregation: %w\", err)\n\t}\n\n\tvar buckets []bucket\n\tif err := cursor.All(ctx, &buckets); err != nil {\n\t\treturn nil, fmt.Errorf(\"error decoding buckets: %w\", err)\n\t}\n\n\treturn buckets, nil\n}\n\nfunc idRangesFromBuckets(buckets []bucket, outerRange idRange) []idRange {\n\tif len(buckets) == 0 {\n\t\treturn nil\n\t}\n\n\tranges := make([]idRange, len(buckets))\n\n\tfor i := 0; i < len(buckets); i++ {\n\t\tsubRange := idRange{}\n\n\t\tif i == 0 {\n\t\t\tsubRange.MinInclusive = outerRange.MinInclusive\n\t\t\tsubRange.Min = outerRange.Min","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/id_range_split.go#L107-L143","documentation":"After starting the $bucketAuto aggregation, getBuckets drains the cursor with cursor.All(ctx, &buckets). If iterating or BSON-decoding the bucket documents into the internal bucket struct fails, this error is wrapped as 'error decoding buckets'. The aggregation ran but its results could not be materialized.","triggerScenarios":"cursor.All fails mid-iteration: server connection drops while streaming results, a bucket document has an unexpected shape the driver cannot decode into the bucket struct, or the context is canceled during iteration.","commonSituations":"Cursor timeout / cursor not found on long-running aggregations against busy servers; driver/server version mismatch producing fields the decoder rejects; network flakiness during large result streaming during split planning.","solutions":["Read the wrapped cause; decode errors indicate an unexpected response shape — check driver/server version compatibility","Increase cursor batch lifetime / keep-alive to avoid cursor timeouts on slow servers","Retry the pipeline; a transient network drop during cursor iteration often succeeds on a second run","Confirm the connected driver version matches the server (e.g. use a recent mongo-driver for newer servers)","Consider the splitVector strategy if bucketAuto repeatedly fails to materialize"],"exampleFix":"// before\nrequire.NoError(t, err) // production code failed on cursor timeout\n// after — server-side: raise cursor idle timeout\n// db.adminCommand({setParameter: 1, cursorTimeoutMillis: 600000})\nsplits, err := bucketAutoSplits(ctx, collection, r, numSplits, bundleSize)","handlingStrategy":"retry","validationCode":"// ensure cursor survives iteration\nvar alive struct{ CursorTimeoutMillis int }\ndb.RunCommand(ctx, bson.D{{Key:\"getParameter\", Value:1}, {Key:\"cursorTimeoutMillis\", Value:1}}).Decode(&alive)","typeGuard":null,"tryCatchPattern":"buckets, err := getBuckets(ctx, coll, pipeline)\nif err != nil && strings.Contains(err.Error(), \"cursor\") {\n\tbuckets, err = retryWithBackoff(ctx, getBuckets, coll, pipeline)\n}","preventionTips":["Raise cursorTimeoutMillis on busy servers","Keep driver version matched to server BSON features","Avoid huge batch sizes over flaky networks","Add bounded retries around split planning"],"tags":["mongodb","go","decoding","aggregation"],"backgroundTag":"bson-decode-failed","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"}