Skip to content

Commit 85d1327

Browse files
authored
Force localhost when lookup the metadata (#317)
* Force localhost when the locator is in localhost and the dnslookup fails * part of #315 --------- Signed-off-by: Gabriele Santomaggio <g.santomaggio@gmail.com>
1 parent 077c157 commit 85d1327

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/stream/client.go

Lines changed: 16 additions & 0 deletions
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)
@@ -688,6 +689,21 @@ func (c *Client) BrokerLeader(stream string) (*Broker, error) {
688689

689690
streamMetadata.Leader.advPort = streamMetadata.Leader.Port
690691
streamMetadata.Leader.advHost = streamMetadata.Leader.Host
692+
693+
// see: https://github.com/rabbitmq/rabbitmq-stream-go-client/pull/317
694+
_, err := net.LookupIP(streamMetadata.Leader.Host)
695+
if err != nil {
696+
var dnsError *net.DNSError
697+
if errors.As(err, &dnsError) {
698+
if strings.EqualFold(c.broker.Host, "localhost") {
699+
logs.LogWarn("Can't lookup the DNS for %s, error: %s. Trying localhost..", streamMetadata.Leader.Host, err)
700+
streamMetadata.Leader.Host = "localhost"
701+
} else {
702+
logs.LogWarn("Can't lookup the DNS for %s, error: %s", streamMetadata.Leader.Host, err)
703+
}
704+
}
705+
}
706+
691707
return streamMetadata.Leader, nil
692708
}
693709

0 commit comments

Comments
 (0)