From a38c5b8f1d780ce042a53a217af8c56316ed3071 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Tue, 3 May 2022 11:00:59 +0200 Subject: [PATCH] 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 --- cmd/alertmanager/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go index 876996f9..3d9add04 100644 --- a/cmd/alertmanager/main.go +++ b/cmd/alertmanager/main.go @@ -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)