{"record":{"id":"e0b4ba83d736646f","repo":"panjf2000/ants","slug":"this-pool-has-been-closed","errorCode":null,"errorMessage":"this pool has been closed","messagePattern":"this pool has been closed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ants.go","lineNumber":70,"sourceCode":")\n\nconst (\n\t// OPENED represents that the pool is opened.\n\tOPENED = iota\n\n\t// CLOSED represents that the pool is closed.\n\tCLOSED\n)\n\nvar (\n\t// ErrLackPoolFunc will be returned when invokers don't provide function for pool.\n\tErrLackPoolFunc = errors.New(\"must provide function for pool\")\n\n\t// ErrInvalidPoolExpiry will be returned when setting a negative number as the periodic duration to purge goroutines.\n\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\")","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/panjf2000/ants/blob/107e37678122b00e1b365636ce4f80623ba41579/ants.go#L52-L88","documentation":"ErrPoolClosed is returned when submitting to or releasing a pool that has already been closed. Once p.Release() (or a failed ReleaseContext) has shut the pool down, further Submit/retrieve calls (ants.go:544) and ReleaseContext calls (ants.go:433) fail with this sentinel. It signals a lifecycle misuse: the pool must not be used after termination.","triggerScenarios":"Calling pool.Submit(task) after pool.Release(); calling pool.ReleaseContext(ctx) on an already-closed pool; sharing one pool across goroutines where one goroutine releases it while others still submit.","commonSituations":"Graceful-shutdown handlers closing the pool while in-flight producers still submit tasks; server reload/restart code paths; accidental double-Release in defer chains.","solutions":["Check err == ants.ErrPoolClosed after Submit and stop producing (or recreate the pool).","Coordinate shutdown: signal producers to stop (context cancellation / done channel) before calling Release, then Release once.","Guard Release with sync.Once to prevent double-close, and treat closed pool as terminal — do not retry.","If a reboot is intended, create a new pool instance (see TestRebootNewPool)."],"exampleFix":"// before\npool.Release()\nif err := pool.Submit(task); err != nil {\n    return err\n}\n// after\nerr := pool.Submit(task)\nif errors.Is(err, ants.ErrPoolClosed) {\n    return ErrShuttingDown // or recreate pool\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := pool.Submit(task)\nswitch {\ncase errors.Is(err, ants.ErrPoolClosed):\n    return ErrShuttingDown // stop producing; do not retry\ncase err != nil:\n    return err\n}","preventionTips":["Stop all producers (via context or done channel) before calling Release.","Wrap Release in sync.Once to avoid double-close.","Treat pool shutdown as terminal — recreate a new pool instead of reusing a closed one."],"tags":["go","lifecycle","closed-resource","concurrency"],"backgroundTag":"invalid-state-transition","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"}