Go WaitGroup: Avoiding a Subtle Bug

Davin Hills
Oct 28, 2020

--

TLDR: Typically this means the calls to Add should execute before the statement creating the goroutine or other event to be waited for — WaitGroup Docs

Correct

…and here it is the way I originally wrote it. The below code is WRONG don’t use.

The correct way is documented but without running into the issue the documentation didn’t register with me that the above code is wrong and won’t work.

That’s all really. Hoping it prevents the issue for someone else trying to make go wrappers to handle goroutines.

--

--

Davin Hills
Davin Hills

Written by Davin Hills

30+ years of experience in software engineering and architecture.

Responses (1)