mirror of
https://github.com/minio/minio.git
synced 2024-12-24 06:05:55 -05:00
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:
parent
013773065c
commit
6b9805e891
@ -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…
Reference in New Issue
Block a user