Skip to content

Commit

Permalink
attack: early cancel ctx only when there's no err
Browse files Browse the repository at this point in the history
This fixes a bug introduced in 074c530 where we'd be cancelling the
racing go-routines even when the first one produced an error, hence
returning an error.

Signed-off-by: Tomás Senart <tsenart@gmail.com>
  • Loading branch information
tsenart committed Jul 24, 2023
1 parent 3fd94ee commit e49c367
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ func DNSCaching(ttl time.Duration) func(*Attacker) {
for _, ip := range ips {
go func(ip string) {
conn, err := dial(ctx, network, net.JoinHostPort(ip, port))
cancel()
if err == nil {
cancel()
}
ch <- result{conn, err}
}(ip)
}
Expand Down

0 comments on commit e49c367

Please sign in to comment.