{"id":"23ab3e728e2ca4f4","repo":"go-redis/redis","slug":"maxworkers-must-be-greater-than-or-equal-to-0","errorCode":null,"errorMessage":"MaxWorkers must be greater than or equal to 0","messagePattern":"MaxWorkers must be greater than or equal to 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"maintnotifications/errors.go","lineNumber":12,"sourceCode":"package maintnotifications\n\nimport (\n\t\"errors\"\n\n\t\"github.com/redis/go-redis/v9/internal/maintnotifications/logs\"\n)\n\n// Configuration errors\nvar (\n\tErrInvalidRelaxedTimeout             = errors.New(logs.InvalidRelaxedTimeoutError())\n\tErrInvalidHandoffTimeout             = errors.New(logs.InvalidHandoffTimeoutError())\n\tErrInvalidHandoffWorkers             = errors.New(logs.InvalidHandoffWorkersError())\n\tErrInvalidHandoffQueueSize           = errors.New(logs.InvalidHandoffQueueSizeError())\n\tErrInvalidPostHandoffRelaxedDuration = errors.New(logs.InvalidPostHandoffRelaxedDurationError())\n\tErrInvalidEndpointType               = errors.New(logs.InvalidEndpointTypeError())\n\tErrInvalidMaintNotifications         = errors.New(logs.InvalidMaintNotificationsError())\n\tErrMaxHandoffRetriesReached          = errors.New(logs.MaxHandoffRetriesReachedError())\n\n\t// Configuration validation errors\n\n\t// ErrInvalidHandoffRetries is returned when the number of handoff retries is invalid\n\tErrInvalidHandoffRetries = errors.New(logs.InvalidHandoffRetriesError())\n)\n\n// Integration errors\nvar (\n\t// ErrInvalidClient is returned when the client does not support push notifications\n\tErrInvalidClient = errors.New(logs.InvalidClientError())\n)","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/maintnotifications/errors.go#L1-L30","documentation":"Returned by Config.Validate() (maintnotifications/config.go:166-168) when the maintenance-notifications Config.MaxWorkers is set to a negative value. MaxWorkers controls how many on-demand goroutines process connection handoffs during Redis maintenance events (MOVING/MIGRATING). Despite the message, 0 is valid (it triggers auto-calculation based on pool size); only negative values are rejected.","triggerScenarios":"Constructing a Client/ClusterClient whose Options.MaintNotificationsConfig.MaxWorkers is explicitly set below 0, which causes Validate() to return ErrInvalidHandoffWorkers during client init. The validation runs as part of config ApplyDefaults/Validate before the manager is created (manager.go:126).","commonSituations":"A config file or env-derived integer that defaults to -1 as a sentinel; arithmetic that computes worker count from a subtracted pool size; copy-pasting a tuning recipe that assumed 0 was invalid.","solutions":["Set MaxWorkers to 0 (or omit it) to let the library auto-calculate from pool size (config.go applyWorkerDefaults uses min(poolSize/2, max(10, poolSize/3))).","If tuning manually, set MaxWorkers to a positive integer (>=1); any value >=0 passes validation.","Search your config plumbing for any place that uses -1 as an 'unset' marker and convert it to 0 before passing into the maint Config."],"exampleFix":"// before\ncfg := &maintnotifications.Config{MaxWorkers: -1}\nif err := cfg.Validate(); err != nil { panic(err) } // ErrInvalidHandoffWorkers\n\n// after\n// leave zero-valued or set explicitly; 0 means auto-calculate\ncfg := &maintnotifications.Config{MaxWorkers: 0}","handlingStrategy":"validation","validationCode":"if cfg.MaxWorkers < 0 {\n    cfg.MaxWorkers = 0 // 0 == auto-calculate\n}\nif err := cfg.Validate(); err != nil {\n    return fmt.Errorf(\"maint config: %w\", err)\n}","typeGuard":"// MaxWorkers is an int; guard its domain before use.\nfunc validMaxWorkers(n int) bool { return n >= 0 }","tryCatchPattern":null,"preventionTips":["Treat 0 as the explicit 'auto' sentinel for MaxWorkers; never use -1.","Run cfg.Validate() in a unit test over your config-loading code.","Clamp env/config-sourced integers to >=0 before assigning."],"tags":["maintnotifications","config","validation","handoff"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}