add Dial timeout for Kafka broker pings (#17044)

This commit is contained in:
Harshavardhana 2023-04-17 15:45:01 -07:00 committed by GitHub
parent f66625be67
commit 8a9b9832fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) 2015-2021 MinIO, Inc. // Copyright (c) 2015-2023 MinIO, Inc.
// //
// This file is part of MinIO Object Storage stack // This file is part of MinIO Object Storage stack
// //
@ -28,6 +28,7 @@ import (
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/minio/minio/internal/event" "github.com/minio/minio/internal/event"
"github.com/minio/minio/internal/logger" "github.com/minio/minio/internal/logger"
@ -268,9 +269,9 @@ func (target *KafkaTarget) Close() error {
// Check if atleast one broker in cluster is active // Check if atleast one broker in cluster is active
func (k KafkaArgs) pingBrokers() bool { func (k KafkaArgs) pingBrokers() bool {
d := net.Dialer{Timeout: 60 * time.Second}
for _, broker := range k.Brokers { for _, broker := range k.Brokers {
_, dErr := net.Dial("tcp", broker.String()) if _, err := d.Dial("tcp", broker.String()); err == nil {
if dErr == nil {
return true return true
} }
} }

View File

@ -26,6 +26,7 @@ import (
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time"
"github.com/minio/pkg/logger/message/audit" "github.com/minio/pkg/logger/message/audit"
@ -148,18 +149,16 @@ type Config struct {
} }
// Check if atleast one broker in cluster is active // Check if atleast one broker in cluster is active
func (k Config) pingBrokers() error { func (k Config) pingBrokers() (err error) {
var err error d := net.Dialer{Timeout: 60 * time.Second}
for _, broker := range k.Brokers { for _, broker := range k.Brokers {
_, err1 := net.Dial("tcp", broker.String()) _, err = d.Dial("tcp", broker.String())
if err1 != nil { if err != nil {
if err == nil { return err
// Set first error
err = err1
}
} }
} }
return err return nil
} }
// Stats returns the target statistics. // Stats returns the target statistics.