Skip to content

Commit 70efe4d

Browse files
committed
Shorten mutex in DNS probe
1 parent 37272bd commit 70efe4d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

pkg/dns/search.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ func SearchByProbe(name string, max int) ([]model.DNSResult, error) {
2929
go func() {
3030
defer wg.Done()
3131
for domain := range domainChan {
32-
mu.Lock()
33-
if len(result) >= max {
34-
return
35-
}
36-
mu.Unlock()
3732
fullDomain := fmt.Sprintf("%s.%s", name, domain)
3833
ips, err := net.LookupIP(fullDomain)
3934
if err != nil {
4035
errorCount++
4136
}
4237
mu.Lock()
4338
result = append(result, model.DNSResult{FQDN: fullDomain, IPList: ips})
39+
if len(result) >= max {
40+
return
41+
}
4442
mu.Unlock()
4543
}
4644
}()

0 commit comments

Comments
 (0)