From c70f43eb339e4702033baec364ef22840304f67a Mon Sep 17 00:00:00 2001 From: Darren Foong Date: Wed, 20 May 2020 08:30:59 +0000 Subject: [PATCH] Add timeout when pinging Docker daemon (#10) * Add timeout to ping * Tidy code * Handle timeout with correct panic message * Check for context.DeadlineExceeded * Tidy code * Update main.go Co-authored-by: Sergei Egorov --- main.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 297fb42..670a0ab 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,10 @@ func main() { cli, err := client.NewEnvClient() if err == nil { - _, err = cli.Ping(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + _, err = cli.Ping(ctx) } if err != nil {