4 ms·
There's a race condition in Done() between ctx.Value() and close(); two goroutines simultaneously calling Done() can both see Value() ok, then second one callin
by mgsouth 7y ago
There's a race condition in Done() between ctx.Value() and close(); two goroutines simultaneously calling Done() can both see Value() ok, then second one calling close() will panic.
Mixing multiple concurrency coordinators (in this case a context and a channel) is tricky, and Go adds little gotchas to the mix. You need a mutex to make all operations atomic across both the context and channel.
- captplanet 6y agoGood spot!