Skip to content

Commit f9c121e

Browse files
committed
Force localhost
Signed-off-by: Gabriele Santomaggio <g.santomaggio@gmail.com>
1 parent 20110d8 commit f9c121e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/stream/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ func (c *Client) queryPublisherSequence(publisherReference string, stream string
673673
}
674674

675675
func (c *Client) BrokerLeader(stream string) (*Broker, error) {
676+
676677
streamsMetadata := c.metaData(stream)
677678
if streamsMetadata == nil {
678679
return nil, fmt.Errorf("leader error for stream for stream: %s", stream)
@@ -685,9 +686,22 @@ func (c *Client) BrokerLeader(stream string) (*Broker, error) {
685686
if streamMetadata.Leader == nil {
686687
return nil, LeaderNotReady
687688
}
688-
689689
streamMetadata.Leader.advPort = streamMetadata.Leader.Port
690690
streamMetadata.Leader.advHost = streamMetadata.Leader.Host
691+
692+
_, err := net.LookupIP(streamMetadata.Leader.Host)
693+
if err != nil {
694+
var dnsError *net.DNSError
695+
if errors.As(err, &dnsError) {
696+
if strings.EqualFold(c.broker.Host, "localhost") {
697+
logs.LogWarn("DNS error: %s, trying to use localhost", dnsError)
698+
streamMetadata.Leader.Host = "localhost"
699+
} else {
700+
logs.LogWarn("DNS error: %s")
701+
}
702+
}
703+
}
704+
691705
return streamMetadata.Leader, nil
692706
}
693707

0 commit comments

Comments
 (0)