Skip to content

Commit

Permalink
fix(provider): 🚑 confirmation order race condition
Browse files Browse the repository at this point in the history
Signed-off-by: Mario-F <github@fritschen.net>
  • Loading branch information
Mario-F committed Dec 11, 2022
1 parent 0593650 commit 7a43d51
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/externalip/externalip.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetExternalIP(version network.IPVersion) (ExternalIP, error) {
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(pList), func(i, j int) { pList[i], pList[j] = pList[j], pList[i] })

var found string
found := make(map[string]int)
for _, p := range pList {
ip, err := p.GetIP()
if err != nil {
Expand All @@ -42,12 +42,12 @@ func GetExternalIP(version network.IPVersion) (ExternalIP, error) {
}
logger.Debugf("Name: %+v, IP: %+v", p.ProviderName, ip)
// found is equal ip means that is the second confirmation
if found == ip {
if found[ip] > 0 {
logger.Debugf("Second confirmation for IP: %+v", ip)
result.IP = ip
return result, nil
}
found = ip
found[ip]++
}

return result, errors.New("at least 2 providers needs to confirm external ip")
Expand Down

0 comments on commit 7a43d51

Please sign in to comment.