diff --git a/internal/updater/cyberghost.go b/internal/updater/cyberghost.go index 6f02c2fb..85fa0621 100644 --- a/internal/updater/cyberghost.go +++ b/internal/updater/cyberghost.go @@ -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 { diff --git a/internal/updater/pia.go b/internal/updater/pia.go index 38c7c783..1f731520 100644 --- a/internal/updater/pia.go +++ b/internal/updater/pia.go @@ -75,7 +75,6 @@ func (u *updater) updatePIAOld(ctx context.Context) (err error) { return fmt.Errorf("cannot find any hosts in %s", fileName) } region := strings.TrimSuffix(fileName, ".ovpn") - guard <- struct{}{} wg.Add(1) go resolvePIAHostname(ctx, wg, region, hosts, u.lookupIP, errors, serversCh, guard) } @@ -100,9 +99,10 @@ func (u *updater) updatePIAOld(ctx context.Context) (err error) { func resolvePIAHostname(ctx context.Context, wg *sync.WaitGroup, region string, hosts []string, lookupIP lookupIPFunc, - errors chan<- error, serversCh chan<- models.PIAServer, guard chan<- struct{}) { + errors chan<- error, serversCh chan<- models.PIAServer, guard chan struct{}) { + guard <- struct{}{} defer func() { - guard <- struct{}{} + <-guard wg.Done() }() var IPs []net.IP //nolint:prealloc