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.
This commit is contained in:
Anis Elleuch 2020-02-13 06:56:23 +01:00 committed by GitHub
parent 013773065c
commit 6b9805e891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.<TARGET_NAME>.
// * 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
}