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.
master
Anis Elleuch 5 years ago committed by GitHub
parent 013773065c
commit 6b9805e891
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      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 a new target in pkg/event/target package.
// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>. // * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.
// * Handle the configuration in this function to create/add into TargetList. // * 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) { func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, targetIDs []event.TargetID, test bool) (_ *event.TargetList, err error) {
targetList = event.NewTargetList() targetList := event.NewTargetList()
// Automatially close all connections when an error occur
defer func() { defer func() {
if registerErr != nil { // Automatically close all connections to targets when an error occur
if err != nil {
for _, t := range targetList.TargetMap() { for _, t := range targetList.TargetMap() {
_ = t.Close() _ = t.Close()
} }
} }
}() }()
if err := checkValidNotificationKeys(cfg); err != nil { if err = checkValidNotificationKeys(cfg); err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save