{"id":"f21fe35dbbaebe0b","repo":"go-redis/redis","slug":"redis-s-value-d-exceeds-maximum-allowed-value","errorCode":null,"errorMessage":"redis: %s value %d exceeds maximum allowed value %d","messagePattern":"redis: (.+?) value (.+?) exceeds maximum allowed value (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/util/convert.go","lineNumber":35,"sourceCode":"\tcase \"nan\", \"-nan\":\n\t\treturn math.NaN(), nil\n\t}\n\treturn strconv.ParseFloat(s, 64)\n}\n\n// MustParseFloat is like ParseFloat but panics on parse errors.\nfunc MustParseFloat(s string) float64 {\n\tf, err := ParseStringToFloat(s)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"redis: failed to parse float %q: %v\", s, err))\n\t}\n\treturn f\n}\n\n// SafeIntToInt32 safely converts an int to int32, returning an error if overflow would occur.\nfunc SafeIntToInt32(value int, fieldName string) (int32, error) {\n\tif value > math.MaxInt32 {\n\t\treturn 0, fmt.Errorf(\"redis: %s value %d exceeds maximum allowed value %d\", fieldName, value, math.MaxInt32)\n\t}\n\tif value < math.MinInt32 {\n\t\treturn 0, fmt.Errorf(\"redis: %s value %d is below minimum allowed value %d\", fieldName, value, math.MinInt32)\n\t}\n\treturn int32(value), nil\n}\n","sourceCodeStart":17,"sourceCodeEnd":42,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/internal/util/convert.go#L17-L42","documentation":"Returned by util.SafeIntToInt32 when an int value exceeds math.MaxInt32 (2,147,483,647). go-redis uses it in newConnPool/newPubSubPool to clamp pool sizing fields (PoolSize, MinIdleConns, MaxIdleConns, MaxActiveConns) into the int32 the internal pool struct expects. The fieldName in the message identifies which option overflowed.","triggerScenarios":"Constructing a Client/PubSub pool on a 64-bit host with a pool option set above MaxInt32, e.g. Options{PoolSize: 1 << 40} or reading such a value from config/env. Any caller of util.SafeIntToInt32 passing an out-of-range int.","commonSituations":"Mis-scaled config (multiplying by a factor that blows past 2^31), an env var parsed as a raw large number, or a bug where bytes vs counts get confused. Practically only reachable on 64-bit builds since int is 32-bit elsewhere.","solutions":["Cap the offending option at a sane value (PoolSize in the low thousands is already extreme).","If the value comes from env/config, validate and clamp it before assigning to Options.","Leave the option at 0 so go-redis applies its default (10*GOMAXPROCS for PoolSize)."],"exampleFix":"// before\nopt := &redis.Options{PoolSize: 1 << 40}\n// after\nopt := &redis.Options{PoolSize: 1000}","handlingStrategy":"validation","validationCode":"func clampPoolField(name string, v int) (int32, error) {\n    return util.SafeIntToInt32(v, name)\n}\n// before building the client:\nif _, err := util.SafeIntToInt32(opt.PoolSize, \"PoolSize\"); err != nil { return err }","typeGuard":"func isValidPoolInt(v int) bool { return v >= math.MinInt32 && v <= math.MaxInt32 }","tryCatchPattern":null,"preventionTips":["Treat pool sizes as small counts; never derive them from byte magnitudes.","Clamp env-derived pool config to a sane maximum before assigning.","Leave the field 0 to accept the go-redis default unless you have measured a need."],"tags":["config","pool","validation"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}