avoid deadlock

This commit is contained in:
Zack Scholl 2022-04-25 06:25:25 -07:00
parent 35652e60a3
commit 80539f27c3
1 changed files with 9 additions and 6 deletions

View File

@ -98,17 +98,20 @@ func lookup(address string) (ipaddress string, err error) {
if !INTERNAL_DNS {
return localLookupIP(address)
}
result := make(chan string, len(publicDns))
type Result struct {
s string
err error
}
result := make(chan Result, len(publicDns))
for _, dns := range publicDns {
go func(dns string) {
s, err := remoteLookupIP(address, dns)
if err == nil {
result <- s
}
var r Result
r.s, r.err = remoteLookupIP(address, dns)
result <- r
}(dns)
}
for i := 0; i < len(publicDns); i++ {
ipaddress = <-result
ipaddress = (<-result).s
if ipaddress != "" {
return
}