Repository navigation
refactor: replace creachadair/taskgroup with x/sync/errgroup and ban it - #1333
Conversation
Drop github.com/creachadair/taskgroup in favor of the already-direct golang.org/x/sync/errgroup dependency, a net dependency removal. The team no longer trusts taskgroup on supply-chain grounds (upstream ships an anti-AI canary string in its README); a supply-chain audit found the code clean but the project is being dropped on trust. Two call sites: - internal/mempool/mempool.go: trivial drop-in. SetLimit + Go reproduces taskgroup's Limit + start blocking-when-full behavior; launch/Flush/Wait ordering and the task body are unchanged. - scripts/keymigrate/migrate.go: errgroup runs task funcs concurrently, so the error aggregation that taskgroup invoked serially is now guarded by a sync.Mutex to avoid a data race. Collect-all-errors semantics and the exact error message format are preserved. Add a CI-enforced gomodguard ban so taskgroup cannot return. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR migrates the codebase away from the external ChangesTaskgroup to errgroup migration
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/mempool/mempool.go (1)
787-815:⚠️ Potential issue | 🟠 Majorinternal/mempool/mempool.go (lines 787-815): errgroup SetLimit backpressures spawning and delays Flush
Withg.SetLimit(2 * runtime.NumCPU()), the loop that callsg.Go(...)can block once 2*NumCPU rechecks are in-flight, sotxmp.proxyAppConn.Flush(ctx)is no longer guaranteed to run only after enqueueing allCheckTxrechecks (it effectively happens per batch).
Ensure theabciclient.Clientimplementation doesn’t rely onFlushto drive/complete queuedCheckTx; otherwise this can deadlock or materially hurt recheck availability. Prefer moving concurrency control into the workers (worker pool / semaphore) so the submission loop can reachFlushdeterministically.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/mempool/mempool.go` around lines 787 - 815, The current use of errgroup.SetLimit(2 * runtime.NumCPU()) causes the g.Go spawning loop to block once the limit is reached, so txmp.proxyAppConn.Flush(ctx) may run before all CheckTx requests are enqueued; move concurrency throttling out of the errgroup spawn path so the submission loop always enqueues all wtxs then Flush is called. Specifically, remove or avoid using g.SetLimit for controlling CheckTx parallelism and instead apply a worker-pool/semaphore inside the goroutine body (e.g., a buffered channel or semaphore acquired before calling CheckTx and released after handleRecheckResult completes), keep using g.Go/g.Wait only to wait for completion, and ensure txmp.proxyAppConn.Flush(ctx) is called after the for loop that enqueues all wtxs; reference symbols: g.SetLimit, g.Go, g.Wait, txmp.proxyAppConn.Flush, wtxs, handleRecheckResult.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@internal/mempool/mempool.go`:
- Around line 787-815: The current use of errgroup.SetLimit(2 *
runtime.NumCPU()) causes the g.Go spawning loop to block once the limit is
reached, so txmp.proxyAppConn.Flush(ctx) may run before all CheckTx requests are
enqueued; move concurrency throttling out of the errgroup spawn path so the
submission loop always enqueues all wtxs then Flush is called. Specifically,
remove or avoid using g.SetLimit for controlling CheckTx parallelism and instead
apply a worker-pool/semaphore inside the goroutine body (e.g., a buffered
channel or semaphore acquired before calling CheckTx and released after
handleRecheckResult completes), keep using g.Go/g.Wait only to wait for
completion, and ensure txmp.proxyAppConn.Flush(ctx) is called after the for loop
that enqueues all wtxs; reference symbols: g.SetLimit, g.Go, g.Wait,
txmp.proxyAppConn.Flush, wtxs, handleRecheckResult.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 16761fcf-dace-4bd0-a64e-65d7da3d53d7
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (4)
.golangci.ymlgo.modinternal/mempool/mempool.goscripts/keymigrate/migrate.go
💤 Files with no reviewable changes (1)
- go.mod
Issue being fixed or feature implemented
golang.org/x/sync/errgroupis already a direct dependency(
go.modhasgolang.org/x/sync v0.20.0), so swapping to it and removingtaskgroup is a net dependency removal — one fewer module in
go.mod/go.sum.What was done?
Replaced taskgroup with
golang.org/x/sync/errgroupat the only two call sites,dropped the dependency, and added a CI-enforced ban so it can't return.
1.
internal/mempool/mempool.go(recheck loop) — trivial drop-in.taskgroup.New(nil).Limit(2*runtime.NumCPU())becomes a zero-valueerrgroup.GroupwithSetLimit(2*runtime.NumCPU());start(...)becomesg.Go(...).errgroup.Goblocks until a worker slot frees up, exactlyreproducing taskgroup's
Limit+startblocking-when-full behavior. Thelaunch-loop →
Flush→Waitordering and the task body are unchanged, andthe result is still discarded (
_ = g.Wait()).2.
scripts/keymigrate/migrate.go(Migrate) — one concurrency subtlety.taskgroup invoked its error handler serially from a single goroutine, which
is why the original
errs = append(...)aggregation was lock-free. errgroup runstask funcs concurrently, so the aggregation is now guarded by a
sync.Mutexto avoid a data race. The point of the original handler was to collect all
errors (not just the first), so that behavior is preserved — every failing task
appends its error before returning. The exact error message format
(
"encountered errors during migration: %q") is unchanged. Verified clean undergo test -race.3. Dependency drop.
go mod tidyremovesgithub.com/creachadair/taskgroup v0.14.2from bothgo.modandgo.sum(the shared
creachadair/mdstransitive dep stays — it's pulled by othercreachadair/*modules).4. CI-enforced ban (
.golangci.yml). Enabled thegomodguardlinter(golangci-lint v2 schema, matching the pinned
@v2.8) with a singleblocked-modules entry for taskgroup — recommending
golang.org/x/sync/errgroupand citing the trust reason. No
allowedlist, so no other module is affected.Any future taskgroup import now fails lint.
How Has This Been Tested?
make build— green (BLS native dependency +tenderdashbinary link).go vet ./internal/mempool/... ./scripts/keymigrate/...— clean.go test -race -count=1 -tags deadlock ./internal/mempool/...— pass.go test -race -count=1 ./scripts/keymigrate/...— pass (mutex prevents theaggregation data race).
[email protected] config verify— config validates against the v2.8 schema.[email protected]— no gomodguard violation (taskgroup is gone), and theban was positively verified: temporarily re-adding the import produces
import of package github.com/creachadair/taskgroup is blocked ... golang.org/x/sync/errgroup is a recommended module (gomodguard).gofmt -l/goimports -local github.com/dashpay/tenderdash— clean on bothedited files.
go mod tidyleaves no further diff;taskgroupabsent fromgo.mod/go.sum.Breaking Changes
None. Internal/tooling refactor only — no public API, wire format, or behavior
change. Concurrency semantics at both call sites are preserved.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit