Skip to content

Conversation

@s4ymur
Copy link

@s4ymur s4ymur commented Apr 10, 2025

Problem

The following scenario is possible and it is leads to data race:

  1. In recover() branch wait group is released
  2. Then it is possible to read errs
  3. But at the same time other goroutine still can write to errs

Thus Race Detector catches concurrent read-write.

Proposed solution

Call wg.Done() by defer. Then the algorithm will look as follows:

  1. Write to errs
  2. wg.Done()
  3. Read errs

In this solution reads go strictly after writes.

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.

1 participant