Skip to content

Commit a38c5b8

Browse files
authored
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 <[email protected]>
1 parent 710588f commit a38c5b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: cmd/alertmanager/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ func run() int {
347347
defer alerts.Close()
348348

349349
var disp *dispatch.Dispatcher
350-
defer disp.Stop()
350+
defer func() {
351+
disp.Stop()
352+
}()
351353

352354
groupFn := func(routeFilter func(*dispatch.Route) bool, alertFilter func(*types.Alert, time.Time) bool) (dispatch.AlertGroups, map[model.Fingerprint][]string) {
353355
return disp.Groups(routeFilter, alertFilter)

0 commit comments

Comments
 (0)