Appearance
Problem Solving
Troubleshooting Common Issues
- "Task manager is shutting down: cannot queue task": This error occurs if you attempt to
QueueTask
,QueueTaskWithPriority
,QueueTaskOnce
,QueueTaskWithPriorityOnce
, orRunTask
aftermanager.Stop()
ormanager.Kill()
has been called, or if theCtx
provided duringNewTaskManager
initialization has been cancelled. Ensure tasks are only submitted while the manager is actively running. - Resource Creation Failure: If your
OnCreate
function returns an error,tasker
will log it, and the associated worker will not start (or aRunTask
call will fail). Ensure your resource creation logic is robust and handles transient issues gracefully. - Workers Not Starting/Stopping as Expected:
- Verify your
WorkerCount
andMaxWorkerCount
settings intasker.Config
. - For dynamic scaling (bursting), ensure
BurstInterval
is configured and not set to 0. - Check that your main
context.Context
(passed asCtx
inConfig
) and itscancel
function are managed correctly, especially for graceful shutdown scenarios. - Review your
CheckHealth
logic; an incorrect implementation might lead to workers constantly restarting (thrashing) or not restarting when they should.
- Verify your
- Deadlocks/Goroutine Leaks: While
tasker
is designed to prevent these within its core logic, improper usage (e.g., blocking indefinitely within yourOnCreate
,OnDestroy
, or task functions, or not using buffered channels for task results outside the library) can lead to such issues. Always ensure your custom functions (OnCreate
,OnDestroy
,taskFunc
) do not block indefinitely. - Task Panics: It is generally recommended that your task functions (the
func(context.Context, R) (E, error)
you pass toQueueTask
etc.) internally recover from panics and convert them into errors. If a panic occurs and is not recovered within the task function itself, it will crash the specific worker goroutine that was executing it. Whiletasker
will detect the worker's exit and attempt to replace it, unhandled panics can lead to unexpected behavior, lost task results, and potential resource leaks ifOnDestroy
is not called due to an abrupt exit.