From 6b9805e891c4ec130d5488baa1617f1b1a66b536 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 13 Feb 2020 06:56:23 +0100 Subject: [PATCH] fix: Avoid crash when there is an error testing a target notif (#8986) RegisterNotificationTargets() cleans up all connections that it makes to notification targets when an error occurs during its execution. However there is a typo in the code that makes the function to always try to access to a nil pointer in the defer code since the function in question will always return nil in the case of any error. This commit fixes the typo in the code. --- cmd/config/notify/parse.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/config/notify/parse.go b/cmd/config/notify/parse.go index dbe2d96a5..944c10f35 100644 --- a/cmd/config/notify/parse.go +++ b/cmd/config/notify/parse.go @@ -65,19 +65,19 @@ func GetNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport // * Add a new target in pkg/event/target package. // * Add newly added target configuration to serverConfig.Notify.. // * Handle the configuration in this function to create/add into TargetList. -func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, targetIDs []event.TargetID, test bool) (targetList *event.TargetList, registerErr error) { - targetList = event.NewTargetList() +func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, targetIDs []event.TargetID, test bool) (_ *event.TargetList, err error) { + targetList := event.NewTargetList() - // Automatially close all connections when an error occur defer func() { - if registerErr != nil { + // Automatically close all connections to targets when an error occur + if err != nil { for _, t := range targetList.TargetMap() { _ = t.Close() } } }() - if err := checkValidNotificationKeys(cfg); err != nil { + if err = checkValidNotificationKeys(cfg); err != nil { return nil, err }