cmd/tailscale: exit loop when timeout and pingArgs.num are met

Currently if you use '-c' and ping a host that times out, ping will
continue running indefinitely. This change exits the loop with "no
reply" when we time out, hit the value specified by '-c' and do not
have anyPong. If we have anyPong it returns nil.

Signed-off-by: Aaron Bieber <aaron@bolddaemon.com>
This commit is contained in:
Aaron Bieber 2022-06-11 12:09:46 -06:00 committed by Brad Fitzpatrick
parent aa37aece9c
commit 3f4fd64311
1 changed files with 6 additions and 0 deletions

View File

@ -121,6 +121,12 @@ func runPing(ctx context.Context, args []string) error {
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
printf("ping %q timed out\n", ip)
if n == pingArgs.num {
if !anyPong {
return errors.New("no reply")
}
return nil
}
continue
}
return err