Handle worker Goexit cleanup and discard orphaned queued tasks

This commit is contained in:
2026-10-20 21:29:45 +08:00
parent aa93168583
commit 5bf542fc67
3 changed files with 334 additions and 5 deletions

View File

@@ -26,9 +26,10 @@ After a task finishes, a worker exits immediately only when `total > min` and
the number of *other* idle workers is greater than `min/2`. There is no idle
timeout. A task panic is logged and that worker continues with later tasks.
Tasks should return normally or panic. Do not call `runtime.Goexit` from a task:
it terminates the worker and may leave `Close` waiting indefinitely. Call
`Close` from outside pool tasks so it does not wait for itself.
Tasks should return normally or panic. `runtime.Goexit` terminates its worker
without replacement. If the last worker exits this way, queued accepted tasks
are discarded so `Close` can return; if other workers remain, they keep the
queue. Call `Close` from outside pool tasks so it does not wait for itself.
A task may submit another task to the same pool. If all workers block submitting
to a full queue, the caller must resolve that deadlock in its task logic.