supervisor: Wait for notifiers to shut down
When stopping a supervised process we may leak the Goroutines that notify listeners of events. This causes flaky tests from time to time:
panic: goroutines running: found unexpected goroutines:
[Goroutine 89 in state select, with gitlab.com/gitlab-org/gitaly/v15/internal/supervisor.(*Process).notifyEvent on top of the stack:
goroutine 89 [select]:
gitlab.com/gitlab-org/gitaly/v15/internal/supervisor.(*Process).notifyEvent(0xc0005b2320, 0x1, 0xd9b2)
/builds/gitlab-org/gitaly/internal/supervisor/supervisor.go:115 +0x131
created by gitlab.com/gitlab-org/gitaly/v15/internal/supervisor.watch
/builds/gitlab-org/gitaly/internal/supervisor/supervisor.go:208 +0x107b
]
goroutine 1 [running]:
gitlab.com/gitlab-org/gitaly/v15/internal/testhelper.mustHaveNoGoroutines()
/builds/gitlab-org/gitaly/internal/testhelper/leakage.go:40 +0x6d6
gitlab.com/gitlab-org/gitaly/v15/internal/testhelper.Run.func1({0x0, 0x0, 0xa0?}, 0x2ae4820?)
/builds/gitlab-org/gitaly/internal/testhelper/configure.go:73 +0x365
gitlab.com/gitlab-org/gitaly/v15/internal/testhelper.Run(0xc000081168?, {0x0, 0x0, 0x0})
/builds/gitlab-org/gitaly/internal/testhelper/configure.go:74 +0x65
gitlab.com/gitlab-org/gitaly/v15/internal/supervisor.TestMain(...)
/builds/gitlab-org/gitaly/internal/supervisor/supervisor_test.go:21
main.main()
_testmain.go:55 +0x32c
Fix this by synchronizing notifiers via a wait group. See e.g. https://gitlab.com/gitlab-org/gitaly/-/jobs/3718134177.