Stopped task workers strand result receivers

perfloop-oss/gronx · Resource Leak

https://perfloop.ai/t/oss/case_caxr0tyjst

Verdict

VERIFIED · settled 2026-11-12 · merged as adhocore/gronx#81

What happened: The check fails before this change and passes with it.

Hypothesis

A task admitted just before Stop can leave its result-handling goroutine blocked after the tracked worker exits. Scheduler accounting can drain while that goroutine remains alive. The supported event order is established, but its deployed frequency and retained-memory cost are unknown.

For each task that passes canRun, runTasks creates an unbuffered result channel and launches doRun and doOut. If the worker observes abort or timeout at doRun's initial check, it returns without sending or closing the channel. doOut waits on an unconditional receive. Only the worker is included in the wait group. Successful callbacks instead send a result, so this leak claim does not apply to every dispatch. Even successful dispatches incur the separate channel and receiver; their CPU and allocation cost is unmeasured.

At revision 9c2fea176d500c5358f59f73f782a312e79d489b, a temporary observation-only gate held an admitted worker before its flag check. Stop completed before the gate opened. Running go test -count=1 -run '^TestPerfloopLifecycleProbe$' -v ./pkg/tasker showed zero callback calls and completed worker accounting, but the receiver did not terminate within 40 milliseconds. Source supplies no later sender. The probe supplied a message only afterward for cleanup. The non-overlap flag also remained acquired; this does not establish a separate restart failure.

This differs from the prior stop-flag race: the gate orders the accesses, and synchronizing those flags alone does not supply the missing completion. The implementation in https://github.com/adhocore/gronx/pull/79 changes due-check wrappers, not this handoff.

The first Case check should retain the ordered admission/Stop assertion and require completion ownership to drain. Cover normal and error callbacks, cutoff, and both overlap modes as regression controls. Changing completion ownership adds bookkeeping complexity and can change logging completion timing, which must be checked. A quiet dispatch benchmark is an optional way to cost the broader handoff removal, not evidence of production savings.

Change to test: Give each admitted task one tracked completion owner, with result handling and release of non-overlap admission covered on every exit. Eliminate the separate one-shot result receiver where possible while preserving callback concurrency and successful/error reporting.

Where it lives

perfloop-oss/gronx · pkg/tasker/tasker.go

Evidence

The check fails before this change and passes with it: `For each registered task whose Tasker.canRun admission succeeds, when Stop or cutoff is ordered before the worker's initial check, the callback is skipped, result handling leaves no blocked goroutine, and non-overlap admission is released; callbacks that return have success/error output completed before task accounting drains.`

Checks: 1 of 1 passed. Verification: no defect found.

Timeline