Skip to content

Commit

Permalink
Add timeout when pinging Docker daemon (#10)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
darrenfoong and bsideup authored May 20, 2020
1 parent ef4ff30 commit c70f43e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c70f43e

Please sign in to comment.