{"record":{"id":"5cda02736c2a3b14","repo":"vitessio/vitess","slug":"maxsize-can-t-be-less-than-minsize","errorCode":null,"errorMessage":"maxSize can't be less than minSize","messagePattern":"maxSize can't be less than minSize","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/bucketpool/bucketpool.go","lineNumber":51,"sourceCode":"\t\t\tNew: func() any { return makeSlicePointer(size) },\n\t\t},\n\t}\n}\n\n// Pool is actually multiple pools which store buffers of specific size.\n// i.e. it can be three pools which return buffers 32K, 64K and 128K.\ntype Pool struct {\n\tminSize int\n\tmaxSize int\n\tpools   []*sizedPool\n}\n\n// New returns Pool which has buckets from minSize to maxSize.\n// Buckets increase with the power of two, i.e with multiplier 2: [2b, 4b, 16b, ... , 1024b]\n// Last pool will always be capped to maxSize.\nfunc New(minSize, maxSize int) *Pool {\n\tif maxSize < minSize {\n\t\tpanic(\"maxSize can't be less than minSize\")\n\t}\n\tconst multiplier = 2\n\tvar pools []*sizedPool\n\tcurSize := minSize\n\tfor curSize < maxSize {\n\t\tpools = append(pools, newSizedPool(curSize))\n\t\tcurSize *= multiplier\n\t}\n\tpools = append(pools, newSizedPool(maxSize))\n\treturn &Pool{\n\t\tminSize: minSize,\n\t\tmaxSize: maxSize,\n\t\tpools:   pools,\n\t}\n}\n\nfunc (p *Pool) findPool(size int) *sizedPool {\n\tif size > p.maxSize {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/bucketpool/bucketpool.go#L33-L69","documentation":"bucketpool.New builds buckets from minSize up to maxSize, doubling each time; it panics if maxSize < minSize because no valid bucket range would exist. This is a programming error guarded at construction time.","triggerScenarios":"Calling bucketpool.New(minSize, maxSize) with maxSize less than minSize, e.g. swapped arguments or a config where the max buffer size was reduced below the min.","commonSituations":"Swapped parameters (New(max, min)); configuration validation done in the wrong order; tests probing boundary behavior.","solutions":["Pass arguments in the correct order: New(minSize, maxSize)","Validate config at load time so maxSize >= minSize before constructing the pool","If the caller computes sizes dynamically, clamp maxSize up to minSize"],"exampleFix":"// before\npool := bucketpool.New(8192, 1024) // swapped\n// after\npool := bucketpool.New(1024, 8192)","handlingStrategy":"validation","validationCode":"func safeNewBucketPool(minSize, maxSize int) *bucketpool.Pool {\n    if maxSize < minSize {\n        panic(fmt.Sprintf(\"invalid bucket pool sizes: min=%d max=%d\", minSize, maxSize))\n    }\n    return bucketpool.New(minSize, maxSize)\n}","typeGuard":"func validPoolSizes(minSize, maxSize int) bool { return maxSize >= minSize }","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Errorf(\"bucketpool construction failed: %v\", r)\n    }\n}()","preventionTips":["Validate size config at startup before constructing pools","Keep min/max size constants adjacent to avoid argument swap","Add unit tests covering boundary sizes"],"tags":["bucketpool","panic","programming-error"],"backgroundTag":"invalid-argument-panic","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}