Fix stopping of nil Dispatcher (#2897)

The function value and parameters of a defer statement are immediately
evaluated, so this "disp" value is always nil, and calling Stop() on a nil
dispatcher is a no-op, so this does nothing, but wrapping it in a closure
that refers to "disp" fixes it.

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2022-05-03 11:00:59 +02:00 committed by GitHub
parent 710588f10f
commit a38c5b8f1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -347,7 +347,9 @@ func run() int {
defer alerts.Close()
var disp *dispatch.Dispatcher
defer disp.Stop()
defer func() {
disp.Stop()
}()
groupFn := func(routeFilter func(*dispatch.Route) bool, alertFilter func(*types.Alert, time.Time) bool) (dispatch.AlertGroups, map[model.Fingerprint][]string) {
return disp.Groups(routeFilter, alertFilter)