Skip to content

Fix data race on error recording in ErrSizedGroup - #14

Merged
umputun merged 2 commits into
masterfrom
fix-errsizedgroup-race
Aug 18, 2026
Merged

Fix data race on error recording in ErrSizedGroup#14
umputun merged 2 commits into
masterfrom
fix-errsizedgroup-race

Conversation

@paskal

@paskal paskal commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Previously, a worker stored the result of g.err.append(err) back into g.err while a Go call which observed a canceled context read the same field outside the lock, and the race detector reports it as a data race. MultiError.append mutates and returns its own receiver, so the assignment was redundant. After this change the field is only set in the constructor, which also makes errLock unnecessary, as MultiError is thread safe on its own.

TestErrorSizedGroup_CancelWithActiveErrors covers the case and fails under go test -race without the fix.

The two cancel tests allowed 110 started goroutines, but 111 is reachable: 100 submitted before the cancellation, up to 10 running and one more waiting for the semaphore. The bound is 120 now.

paskal added 2 commits August 18, 2026 21:54
Previously, a worker stored the result of g.err.append(err) back into
g.err while a canceled Go call read the same field outside the lock,
which the race detector flags. MultiError.append mutates and returns its
own receiver, so the assignment was redundant; dropping it makes the
field write-once and removes the need for errLock, as MultiError is
already thread safe on its own.
The cancel tests allowed 110 started goroutines, but 111 is reachable:
100 submitted before the cancellation, up to 10 running and one more
waiting for the semaphore.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 32187480544

Coverage decreased (-0.03%) to 98.837%

Details

  • Coverage decreased (-0.03%) from the base build.
  • Patch coverage: 2 of 2 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 172
Covered Lines: 170
Line Coverage: 98.84%
Coverage Strength: 1854.99 hits per line

💛 - Coveralls

@umputun
umputun merged commit 1d64c7b into master Aug 18, 2026
5 of 7 checks passed
@paskal
paskal deleted the fix-errsizedgroup-race branch August 18, 2026 23:03
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.

3 participants