{"record":{"id":"ca329626536a3b8c","repo":"apache/beam","slug":"params-maxbufferingduration-must-be-0-got-s","errorCode":null,"errorMessage":"Params.MaxBufferingDuration must be >= 0; got %s","messagePattern":"Params\\.MaxBufferingDuration must be >= 0; got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/batch/batch.go","lineNumber":192,"sourceCode":"\n\t// MaxBufferingDuration, when > 0, triggers emission of a partial\n\t// batch after this much processing time has elapsed since the\n\t// first element of the current batch was buffered.\n\tMaxBufferingDuration time.Duration\n}\n\nfunc (p Params) validate() error {\n\tif p.BatchSize < 0 {\n\t\treturn fmt.Errorf(\"Params.BatchSize must be >= 0; got %d\", p.BatchSize)\n\t}\n\tif p.BatchSizeBytes < 0 {\n\t\treturn fmt.Errorf(\"Params.BatchSizeBytes must be >= 0; got %d\", p.BatchSizeBytes)\n\t}\n\tif p.BatchSize == 0 && p.BatchSizeBytes == 0 {\n\t\treturn fmt.Errorf(\"Params: at least one of BatchSize or BatchSizeBytes must be > 0\")\n\t}\n\tif p.MaxBufferingDuration < 0 {\n\t\treturn fmt.Errorf(\"Params.MaxBufferingDuration must be >= 0; got %s\", p.MaxBufferingDuration)\n\t}\n\treturn nil\n}\n\nconst (\n\tsizerNone      int32 = 0\n\tsizerPrimitive int32 = 1\n)\n\n// codecCache keeps a per-value-type ElementEncoder/Decoder pair.\ntype codecCache struct {\n\tonce sync.Once\n\tenc  beam.ElementEncoder\n\tdec  beam.ElementDecoder\n}\n\nfunc (c *codecCache) init(t reflect.Type) {\n\tc.once.Do(func() {","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/batch/batch.go#L174-L210","documentation":"Params.MaxBufferingDuration was set to a negative duration, which is meaningless as a time window. validate() rejects it at pipeline-construction time so the transform never runs with an impossible configuration. Fix the Params struct before calling GroupIntoBatches.","triggerScenarios":"Passing Params with MaxBufferingDuration set to a negative time.Duration (e.g. -5*time.Second) to GroupIntoBatches or GroupIntoBatchesWithShardedKey, which calls params.validate().","commonSituations":"Computing a duration from a signed config value or arithmetic that can go negative (e.g. deadline - now after the deadline passed), or typo signs when writing literals like -time.Second.","solutions":["Print the Params value and find where MaxBufferingDuration becomes negative","Correct the config/arithmetic producing the negative duration, or clamp with time.Duration(0) minimum","Call params.validate() yourself before building the pipeline to fail fast","Remove MaxBufferingDuration (leave it 0) if buffering-time limiting is not needed"],"exampleFix":"// before\np := batch.Params{BatchSize: 100, MaxBufferingDuration: -2 * time.Second}\n// after\np := batch.Params{BatchSize: 100, MaxBufferingDuration: 2 * time.Second}","handlingStrategy":"validation","validationCode":"if p.MaxBufferingDuration < 0 { return fmt.Errorf(\"bad MaxBufferingDuration: %s\", p.MaxBufferingDuration) }\nreturn p.validate()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp durations from config to >= 0","Call validate() right after constructing Params","Unit-test negative-duration rejection"],"tags":["go","apache-beam","validation","pipeline-construction"],"backgroundTag":"invalid-argument-value","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"}