Skip to content

Commit

Permalink
preference a privateIP address over loopback addresses
Browse files Browse the repository at this point in the history
- when automatically determining the advertiseAddr use a private
IP address if available over a loopback adddress
- fixes hashicorp#102
  • Loading branch information
woodsaj committed Jan 10, 2017
1 parent 9800c50 commit c84ce87
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions memberlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,19 @@ func (m *Memberlist) setAlive() error {
if !IsPrivateIP(ip.String()) {
continue
}

advertiseAddr = ip
break
// if the ip is a loopback addr, keep trying other interface addresses.
// if no other privateIP addresses are found, the loopback will be used.
if !isLoopbackIP(ip.String()) {
break
}
}

// Failed to find private IP, error
if advertiseAddr == nil {
return fmt.Errorf("No private IP address found, and explicit IP not provided")
} else {
m.logger.Printf("[DEBUG] memberlist: %s selected as advertiseAddr for node", net.IP(advertiseAddr).String())
}

} else {
Expand Down

0 comments on commit c84ce87

Please sign in to comment.