From 80539f27c36e6fc7d970d8d415d3bbf72ec65c02 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 25 Apr 2022 06:25:25 -0700 Subject: [PATCH] avoid deadlock --- src/models/constants.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/models/constants.go b/src/models/constants.go index a6a0066e..8fdb9c0f 100644 --- a/src/models/constants.go +++ b/src/models/constants.go @@ -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 }