{"record":{"id":"bea8cfcf900b966e","repo":"panjf2000/ants","slug":"invalid-size-for-multiple-pool","errorCode":null,"errorMessage":"invalid size for multiple pool","messagePattern":"invalid size for multiple pool","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ants.go","lineNumber":88,"sourceCode":"\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\n\t}()\n\n\tdefaultLogger = Logger(log.New(os.Stderr, \"[ants]: \", log.LstdFlags|log.Lmsgprefix|log.Lmicroseconds))","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/panjf2000/ants/blob/107e37678122b00e1b365636ce4f80623ba41579/ants.go#L70-L106","documentation":"ErrInvalidMultiPoolSize is returned by NewMultiPool, NewMultiPoolWithFunc and NewMultiPoolWithFuncGeneric when the requested number of sub-pools is invalid (e.g. negative). A MultiPool must contain at least one sub-pool, so construction is rejected up front.","triggerScenarios":"ants.NewMultiPool(-1, 10, ants.RoundRobin) or equivalent WithFunc/Generic constructors with a negative or zero pool count (size <= 0).","commonSituations":"Pool count derived from config or NumCPU-based heuristics that compute <= 0; placeholder -1 meaning 'auto' that the constructor does not accept.","solutions":["Pass a positive pool count (>= 1) to the NewMultiPool* constructors.","Normalize config-derived counts: if size <= 0, fall back to runtime.NumCPU() or a fixed default.","If one pool suffices, use NewPool/NewPoolWithFunc instead of MultiPool."],"exampleFix":"// before\nsize := cfg.PoolCount // may be -1\nmp, err := ants.NewMultiPool(size, 10, ants.RoundRobin)\n// after\nif cfg.PoolCount <= 0 {\n    cfg.PoolCount = runtime.NumCPU()\n}\nmp, err := ants.NewMultiPool(cfg.PoolCount, 10, ants.RoundRobin)","handlingStrategy":"validation","validationCode":"if poolCount <= 0 {\n    poolCount = runtime.NumCPU()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Normalize pool counts from config at startup (min 1).","Use NewPool when a single pool suffices.","Derive counts from runtime.NumCPU() rather than sentinel values like -1."],"tags":["go","validation","configuration","multipool"],"backgroundTag":"invalid-argument-value","analyzedSha":"107e37678122b00e1b365636ce4f80623ba41579","analyzedAt":"2026-09-06T13:28:28.492Z","contentChangedAt":"2026-09-06T13:28:28.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}