cluster: don't track FQDN addresses as inital peers (#1416)

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2018-06-15 12:34:50 +02:00 committed by stuart nelson
parent 6a7c912559
commit 8034f137e1
2 changed files with 16 additions and 6 deletions

View File

@ -232,6 +232,9 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
return
}
p.peerLock.RLock()
defer p.peerLock.RUnlock()
now := time.Now()
for _, peerAddr := range peers {
if peerAddr == myAddr {
@ -239,10 +242,16 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
// we don't connect to ourselves.
continue
}
ip, port, err := net.SplitHostPort(peerAddr)
host, port, err := net.SplitHostPort(peerAddr)
if err != nil {
continue
}
ip := net.ParseIP(host)
if ip == nil {
// Don't add textual addresses since memberlist only advertises
// dotted decimal or IPv6 addresses.
continue
}
portUint, err := strconv.ParseUint(port, 10, 16)
if err != nil {
continue
@ -252,7 +261,7 @@ func (p *Peer) setInitialFailed(peers []string, myAddr string) {
status: StatusFailed,
leaveTime: now,
Node: &memberlist.Node{
Addr: net.ParseIP(ip),
Addr: ip,
Port: uint16(portUint),
},
}

View File

@ -179,7 +179,7 @@ func TestRemoveFailedPeers(t *testing.T) {
func TestInitiallyFailingPeers(t *testing.T) {
logger := log.NewNopLogger()
myAddr := "1.2.3.4:5000"
peerAddrs := []string{myAddr, "2.3.4.5:5000", "3.4.5.6:5000"}
peerAddrs := []string{myAddr, "2.3.4.5:5000", "3.4.5.6:5000", "foo.example.com:5000"}
p, err := Join(
logger,
prometheus.NewRegistry(),
@ -200,10 +200,11 @@ func TestInitiallyFailingPeers(t *testing.T) {
p.setInitialFailed(peerAddrs, myAddr)
// We shouldn't have added "our" bind addr to the failed peers list
require.Equal(t, len(peerAddrs)-1, len(p.failedPeers))
// We shouldn't have added "our" bind addr and the FQDN address to the
// failed peers list.
require.Equal(t, len(peerAddrs)-2, len(p.failedPeers))
for _, addr := range peerAddrs {
if addr == myAddr {
if addr == myAddr || addr == "foo.example.com:5000" {
continue
}