Skip to content

errgroup: rewrite worker scheduling with sync.Cond to fix data race and delayed task dispatch - #230

Merged
luduoxin merged 9 commits into
sunmi-OS:mainfrom
noble-gase:main
Jul 6, 2026
Merged

errgroup: rewrite worker scheduling with sync.Cond to fix data race and delayed task dispatch#230
luduoxin merged 9 commits into
sunmi-OS:mainfrom
noble-gase:main

Conversation

@noble-gase

Copy link
Copy Markdown
Contributor

Replace the channel-based worker scheduling with a sync.Cond based implementation.

Fixes

  • Data race: Go() mutated cache/remain without locking; all shared state is now mutex-protected.
  • Delayed dispatch: queued tasks were only flushed inside Wait(); they are now consumed immediately by idle workers via cond.Signal().
  • Lost cancellation cause: return context.Cause(ctx) instead of ctx.Err().

Improvements

  • Spawn workers on demand only when backlog exceeds idle workers.
  • Calling Go() after Wait() now panics with a clear message.
  • Nil out dequeued slice elements to avoid memory retention.

Testing

go test -race ./errgroup/

@luduoxin
luduoxin merged commit 124f5f3 into sunmi-OS:main Jul 6, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants