Skip to content

Commit 074c530

Browse files
committed
attack: ensure go-routines finish in DNSCaching
Signed-off-by: Tomás Senart <[email protected]>
1 parent 174d804 commit 074c530

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/attack.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,23 +344,18 @@ func DNSCaching(ttl time.Duration) func(*Attacker) {
344344
for _, ip := range ips {
345345
go func(ip string) {
346346
conn, err := dial(ctx, network, net.JoinHostPort(ip, port))
347+
cancel()
347348
ch <- result{conn, err}
348349
}(ip)
349350
}
350351

351352
for i := 0; i < cap(ch); i++ {
352-
select {
353-
case <-ctx.Done():
354-
return nil, ctx.Err()
355-
case r := <-ch:
356-
if err = r.err; err != nil {
357-
continue
358-
}
359-
return r.conn, nil
353+
if r := <-ch; conn == nil {
354+
conn, err = r.conn, r.err
360355
}
361356
}
362357

363-
return nil, err
358+
return conn, err
364359
}
365360
}
366361
}

0 commit comments

Comments
 (0)