Skip to content

Commit

Permalink
fixes auto_join for mDNS provider
Browse files Browse the repository at this point in the history
  • Loading branch information
aubrich committed Jan 25, 2024
1 parent e8e739f commit 8b85577
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vault/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"encoding/base64"
"errors"
"fmt"
"net"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -1227,9 +1229,18 @@ func (c *Core) raftLeaderInfo(leaderInfo *raft.LeaderJoinInfo, disco *discover.D
return nil, fmt.Errorf("failed to parse addresses from auto-join metadata: %w", err)
}
for _, ip := range clusterIPs {
if strings.Count(ip, ":") >= 2 && !strings.HasPrefix(ip, "[") {
if count := strings.Count(ip, ":"); count >= 2 && !strings.HasPrefix(ip, "[") {
// An IPv6 address in implicit form, however we need it in explicit form to use in a URL.
ip = fmt.Sprintf("[%s]", ip)
} else if count > 0 && !strings.HasSuffix(ip, "]") {
tmpIp, portStr, err := net.SplitHostPort(ip)
if err == nil {
ip = tmpIp
tmpPort, err := strconv.Atoi(portStr)
if err == nil {
port = uint(tmpPort)
}
}
}
u := fmt.Sprintf("%s://%s:%d", scheme, ip, port)
info := *leaderInfo
Expand Down

0 comments on commit 8b85577

Please sign in to comment.