From 3f4fd64311708ed0c0242a407ca0be9a833acb06 Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Sat, 11 Jun 2022 12:09:46 -0600 Subject: [PATCH] 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 --- cmd/tailscale/cli/ping.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/tailscale/cli/ping.go b/cmd/tailscale/cli/ping.go index 5eb968734..5fe338da5 100644 --- a/cmd/tailscale/cli/ping.go +++ b/cmd/tailscale/cli/ping.go @@ -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