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) }, }