alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Fix silence import: also wait for the error collection goroutine to finish

Open ultrotter opened this issue 1 month ago • 2 comments

As noticed by George Robinson the error collection goroutine in silence import is also not waited for, so we may get an incorrect count when we exit. This adds a done channel for that goroutine, and checks that the error count is correct with a new test.

Signed-off-by: Guido Trotter [email protected]

ultrotter avatar Nov 14 '25 13:11 ultrotter

Looks ok, but I said that with the previous one and now I'm unsure :D

I was wondering if the cleanupDone could be done with https://pkg.go.dev/sync#Once

eg

	var once sync.Once
	closeChannels := func() {
		once.Do(func() {
			close(silencec)
			wg.Wait()
			close(errc)
			<-errDone
			close(errDone)
		})
	}

TheMeier avatar Nov 17 '25 19:11 TheMeier

Looks ok, but I said that with the previous one and now I'm unsure :D

I was wondering if the cleanupDone could be done with https://pkg.go.dev/sync#Once

eg

	var once sync.Once
	closeChannels := func() {
		once.Do(func() {
			close(silencec)
			wg.Wait()
			close(errc)
			<-errDone
			close(errDone)
		})
	}

Done, thanks for the suggestion!

ultrotter avatar Nov 18 '25 14:11 ultrotter