mirror of
https://github.com/minio/minio.git
synced 2025-04-22 11:26:36 -04:00
fix: Avoid closing target in RegisterNotificationTargets (#8966)
This will prevent a double target Close() call when fetchLambdaInfo() is executed (mc admin info) This fixes a crash when mc admin info is called.
This commit is contained in:
parent
de924605a1
commit
502e652b7a
@ -42,7 +42,14 @@ const (
|
|||||||
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport,
|
func TestNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport,
|
||||||
targetIDs []event.TargetID) error {
|
targetIDs []event.TargetID) error {
|
||||||
test := true
|
test := true
|
||||||
_, err := RegisterNotificationTargets(cfg, doneCh, transport, targetIDs, test)
|
targets, err := RegisterNotificationTargets(cfg, doneCh, transport, targetIDs, test)
|
||||||
|
if err == nil {
|
||||||
|
// Close all targets since we are only testing connections.
|
||||||
|
for _, t := range targets.TargetMap() {
|
||||||
|
_ = t.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,8 +65,18 @@ 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) (*event.TargetList, error) {
|
func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, transport *http.Transport, targetIDs []event.TargetID, test bool) (targetList *event.TargetList, registerErr error) {
|
||||||
targetList := event.NewTargetList()
|
targetList = event.NewTargetList()
|
||||||
|
|
||||||
|
// Automatially close all connections when an error occur
|
||||||
|
defer func() {
|
||||||
|
if registerErr != nil {
|
||||||
|
for _, t := range targetList.TargetMap() {
|
||||||
|
_ = t.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
if err := checkValidNotificationKeys(cfg); err != nil {
|
if err := checkValidNotificationKeys(cfg); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -125,9 +142,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range esTargets {
|
for id, args := range esTargets {
|
||||||
@ -142,9 +156,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range kafkaTargets {
|
for id, args := range kafkaTargets {
|
||||||
@ -159,9 +170,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range mqttTargets {
|
for id, args := range mqttTargets {
|
||||||
@ -176,9 +184,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range mysqlTargets {
|
for id, args := range mysqlTargets {
|
||||||
@ -192,9 +197,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range natsTargets {
|
for id, args := range natsTargets {
|
||||||
@ -208,9 +210,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range nsqTargets {
|
for id, args := range nsqTargets {
|
||||||
@ -224,9 +223,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range postgresTargets {
|
for id, args := range postgresTargets {
|
||||||
@ -240,9 +236,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range redisTargets {
|
for id, args := range redisTargets {
|
||||||
@ -256,9 +249,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err = targetList.Add(newTarget); err != nil {
|
if err = targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for id, args := range webhookTargets {
|
for id, args := range webhookTargets {
|
||||||
@ -272,10 +262,6 @@ func RegisterNotificationTargets(cfg config.Config, doneCh <-chan struct{}, tran
|
|||||||
if err := targetList.Add(newTarget); err != nil {
|
if err := targetList.Add(newTarget); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if test {
|
|
||||||
newTarget.Close()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if test {
|
if test {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user