{"record":{"id":"43cb6e366474ab35","repo":"panjf2000/ants","slug":"operation-timed-out","errorCode":null,"errorMessage":"operation timed out","messagePattern":"operation timed out","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ants.go","lineNumber":79,"sourceCode":"\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\")\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 {","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/panjf2000/ants/blob/107e37678122b00e1b365636ce4f80623ba41579/ants.go#L61-L97","documentation":"ErrTimeout is returned by pool.ReleaseTimeout when the graceful release does not complete before the given timeout. ReleaseTimeout wraps ReleaseContext with a context deadline; if the context expires with context.DeadlineExceeded, it is converted to this sentinel (ants.go:422). It means in-flight workers had not finished within the budget.","triggerScenarios":"pool.ReleaseTimeout(d) where d elapses while long-running tasks still occupy workers, so pending task submission times out.","commonSituations":"Shutdown sequences with short drain windows while tasks are long-running (e.g. long HTTP handlers, DB batches); forgetting that blocked Submit waits until a worker is free.","solutions":["Increase the timeout passed to ReleaseTimeout to cover worst-case task duration.","On ErrTimeout, log the incomplete drain and proceed with forced shutdown (or call Release to force close).","Split long tasks into smaller units or support cancellation via task arguments/context so they finish faster.","Stop producers before draining so no new tasks extend the shutdown window."],"exampleFix":"// before\nif err := pool.ReleaseTimeout(time.Second); err != nil {\n    panic(err)\n}\n// after\nif errors.Is(err, ants.ErrTimeout) {\n    log.Warn(\"pool drain timed out; forcing release\")\n    pool.Release()\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := pool.ReleaseTimeout(30 * time.Second)\nif errors.Is(err, ants.ErrTimeout) {\n    log.Warn(\"drain timed out; forcing release\")\n    pool.Release()\n}","preventionTips":["Size the drain timeout to exceed worst-case task duration.","Stop producers before draining.","Make tasks context-aware so they can finish early during shutdown."],"tags":["go","timeout","shutdown","concurrency"],"backgroundTag":"request-timeout","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"}