From d46ece440532ad3d687a38164a91ea98695ec184 Mon Sep 17 00:00:00 2001 From: Kevin Dungs Date: Sat, 1 Aug 2020 15:38:18 +0200 Subject: [PATCH] Start gather goroutine before looping over Scanner. Otherwise gather is blocked when the workers try to write to it after processing their first elements since nothing is reading from it, yet. Thanks to Sean Liao on the Gophers Slack for pointing this out. This resolves #11. --- ch-5/subdomain_guesser/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ch-5/subdomain_guesser/main.go b/ch-5/subdomain_guesser/main.go index 3ebff26..0b784fb 100644 --- a/ch-5/subdomain_guesser/main.go +++ b/ch-5/subdomain_guesser/main.go @@ -119,11 +119,6 @@ func main() { go worker(tracker, fqdns, gather, *flServerAddr) } - for scanner.Scan() { - fqdns <- fmt.Sprintf("%s.%s", scanner.Text(), *flDomain) - } - // Note: We could check scanner.Err() here. - go func() { for r := range gather { results = append(results, r...) @@ -132,6 +127,11 @@ func main() { tracker <- e }() + for scanner.Scan() { + fqdns <- fmt.Sprintf("%s.%s", scanner.Text(), *flDomain) + } + // Note: We could check scanner.Err() here. + close(fqdns) for i := 0; i < *flWorkerCount; i++ { <-tracker