mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
add Dial timeout for Kafka broker pings (#17044)
This commit is contained in:
parent
f66625be67
commit
8a9b9832fd
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user