From 25c31c2c7c2a7c5fd9f2fdf5baacbb5c79fc81db Mon Sep 17 00:00:00 2001 From: Yuri Tseretyan Date: Thu, 2 Mar 2023 14:45:27 -0500 Subject: [PATCH] [v9.4.x] Alerting: Use background context for maintenance function (#64066) Alerting: Use background context for maintenance function (#64065) (cherry picked from commit e760f224024c46fa284d82dc145503b4648dc93a) # Conflicts: # pkg/services/ngalert/notifier/alertmanager.go --- 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 f6aca475f63..a7e739b4b48 100644 --- a/pkg/services/ngalert/notifier/alertmanager.go +++ b/pkg/services/ngalert/notifier/alertmanager.go @@ -102,7 +102,8 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A retention: retentionNotificationsAndSilences, maintenanceFrequency: silenceMaintenanceInterval, maintenanceFunc: func(state alerting.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) }, } @@ -111,7 +112,8 @@ func newAlertmanager(ctx context.Context, orgID int64, cfg *setting.Cfg, store A retention: retentionNotificationsAndSilences, maintenanceFrequency: notificationLogMaintenanceInterval, maintenanceFunc: func(state alerting.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) }, }