Skip to content

Commit

Permalink
Start gather goroutine before looping over Scanner.
Browse files Browse the repository at this point in the history
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 blackhat-go#11.
  • Loading branch information
kdungs committed Aug 1, 2020
1 parent 5b00835 commit d46ece4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions ch-5/subdomain_guesser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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
Expand Down

0 comments on commit d46ece4

Please sign in to comment.