[Solved] Why is WaitGroup.Wait() hanging when using it with go test? [duplicate]


Two issues:

  • don’t copy sync.WaitGroup: from the docs:

    • A WaitGroup must not be copied after first use.
  • you need a wg.Add(1) before launching your work – to pair with the wg.Done()


wg.Add(1) // <- add this

go func (wg *sync.WaitGroup ...) { // <- pointer
}(&wg, quitSig) // <- pointer to avoid WaitGroup copy

https://go.dev/play/p/UmeI3TdGvhg

solved Why is WaitGroup.Wait() hanging when using it with go test? [duplicate]