{"record":{"id":"3cc02bfb7daa377a","repo":"panjf2000/ants","slug":"invalid-load-balancing-strategy","errorCode":null,"errorMessage":"invalid load-balancing strategy","messagePattern":"invalid load-balancing strategy","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ants.go","lineNumber":85,"sourceCode":"\tErrInvalidPoolExpiry = errors.New(\"invalid expiry for pool\")\n\n\t// ErrPoolClosed will be returned when submitting task to a closed pool.\n\tErrPoolClosed = errors.New(\"this pool has been closed\")\n\n\t// ErrPoolOverload will be returned when the pool is full and no workers available.\n\tErrPoolOverload = errors.New(\"too many goroutines blocked on submit or Nonblocking is set\")\n\n\t// ErrInvalidPreAllocSize will be returned when trying to set up a negative capacity under PreAlloc mode.\n\tErrInvalidPreAllocSize = errors.New(\"can not set up a negative capacity under PreAlloc mode\")\n\n\t// ErrTimeout will be returned after the operations timed out.\n\tErrTimeout = errors.New(\"operation timed out\")\n\n\t// ErrInvalidPoolIndex will be returned when trying to retrieve a pool with an invalid index.\n\tErrInvalidPoolIndex = errors.New(\"invalid pool index\")\n\n\t// ErrInvalidLoadBalancingStrategy will be returned when trying to create a MultiPool with an invalid load-balancing strategy.\n\tErrInvalidLoadBalancingStrategy = errors.New(\"invalid load-balancing strategy\")\n\n\t// ErrInvalidMultiPoolSize  will be returned when trying to create a MultiPool with an invalid size.\n\tErrInvalidMultiPoolSize = errors.New(\"invalid size for multiple pool\")\n\n\t// workerChanCap determines whether the channel of a worker should be a buffered channel\n\t// to get the best performance. Inspired by fasthttp at\n\t// https://github.com/valyala/fasthttp/blob/master/workerpool.go#L139\n\tworkerChanCap = func() int {\n\t\t// Use blocking channel if GOMAXPROCS=1.\n\t\t// This switches context from sender to receiver immediately,\n\t\t// which results in higher performance (under go1.5 at least).\n\t\tif runtime.GOMAXPROCS(0) == 1 {\n\t\t\treturn 0\n\t\t}\n\n\t\t// Use non-blocking workerChan if GOMAXPROCS>1,\n\t\t// since otherwise the sender might be dragged down if the receiver is CPU-bound.\n\t\treturn 1","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/panjf2000/ants/blob/107e37678122b00e1b365636ce4f80623ba41579/ants.go#L67-L103","documentation":"ErrInvalidLoadBalancingStrategy is returned by NewMultiPool, NewMultiPoolWithFunc and NewMultiPoolWithFuncGeneric when the load-balancing argument is not one of the supported strategies (ants.RoundRobin or ants.LeastTasks). Passing an arbitrary integer yields this error instead of silently mis-dispatching tasks.","triggerScenarios":"ants.NewMultiPool(10, -1, 8) — here 8 is the strategy slot and is invalid; any construction with a strategy value other than RoundRobin or LeastTasks constants.","commonSituations":"Swapped arguments — passing the task-arg type or a size where the strategy belongs; custom numeric strategies assumed to be valid; refactors renaming constants.","solutions":["Pass ants.RoundRobin or ants.LeastTasks explicitly as the strategy argument.","Check argument order: NewMultiPool(size, div, strategy, options...) — verify the strategy slot.","Validate any config-sourced strategy against the two allowed constants before constructing."],"exampleFix":"// before\nmp, err := ants.NewMultiPool(10, -1, 8)\n// after\nmp, err := ants.NewMultiPool(10, -1, ants.RoundRobin)","handlingStrategy":"validation","validationCode":"func validStrategy(s ants.LoadBalancingStrategy) bool {\n    return s == ants.RoundRobin || s == ants.LeastTasks\n}\nif !validStrategy(strategy) {\n    strategy = ants.RoundRobin\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use the ants.RoundRobin / ants.LeastTasks constants.","Double-check argument order in NewMultiPool(size, div, strategy, opts...).","Whitelist config-supplied strategy strings to the two supported constants."],"tags":["go","invalid-enum","configuration","multipool"],"backgroundTag":"invalid-enum-value","analyzedSha":"107e37678122b00e1b365636ce4f80623ba41579","analyzedAt":"2026-09-06T13:28:28.492Z","contentChangedAt":"2026-09-06T13:28:28.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}