From e760f224024c46fa284d82dc145503b4648dc93a Mon Sep 17 00:00:00 2001 From: Yuri Tseretyan Date: Thu, 2 Mar 2023 14:19:52 -0500 Subject: [PATCH] Alerting: Use background context for maintenance function (#64065) --- pkg/services/ngalert/notifier/alertmanager.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/services/ngalert/notifier/alertmanager.go b/pkg/services/ngalert/notifier/alertmanager.go index 875010fa942..17812a59cc5 100644 --- a/pkg/services/ngalert/notifier/alertmanager.go +++ b/pkg/services/ngalert/notifier/alertmanager.go @@ -103,7 +103,8 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A retention: retentionNotificationsAndSilences, maintenanceFrequency: silenceMaintenanceInterval, maintenanceFunc: func(state alertingNotify.State) (int64, error) { - return fileStore.Persist(ctx, silencesFilename, state) + // Detached context here is to make sure that when the service is shut down the persist operation is executed. + return fileStore.Persist(context.Background(), silencesFilename, state) }, } @@ -112,7 +113,8 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A retention: retentionNotificationsAndSilences, maintenanceFrequency: notificationLogMaintenanceInterval, maintenanceFunc: func(state alertingNotify.State) (int64, error) { - return fileStore.Persist(ctx, notificationLogFilename, state) + // Detached context here is to make sure that when the service is shut down the persist operation is executed. + return fileStore.Persist(context.Background(), notificationLogFilename, state) }, }