Fix guard pattern for max parallel DNS requests

This commit is contained in:
Quentin McGaw
2020-10-12 17:35:46 +00:00
parent ec157f102b
commit ae7fc5fe96
2 changed files with 6 additions and 6 deletions

View File

@@ -38,7 +38,6 @@ func findCyberghostServers(ctx context.Context, lookupIP lookupIPFunc) (servers
}
const domain = "cg-dialup.net"
host := fmt.Sprintf("%s-%s.%s", groupID, countryCode, domain)
guard <- struct{}{}
go tryCyberghostHostname(ctx, lookupIP, host, groupName, region, results, guard)
}
}
@@ -60,9 +59,10 @@ func findCyberghostServers(ctx context.Context, lookupIP lookupIPFunc) (servers
func tryCyberghostHostname(ctx context.Context, lookupIP lookupIPFunc,
host, groupName, region string,
results chan<- models.CyberghostServer, guard chan<- struct{}) {
results chan<- models.CyberghostServer, guard chan struct{}) {
guard <- struct{}{}
defer func() {
guard <- struct{}{}
<-guard
}()
IPs, err := resolveRepeat(ctx, lookupIP, host, 2)
if err != nil || len(IPs) == 0 {