From 422ba60b046f0b2991ab51958e79b65ce472d9e8 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 19 Aug 2021 20:36:24 -0700 Subject: [PATCH] use long-running context for client initialization Signed-off-by: Tonis Tiigi --- bake/remote.go | 2 +- build/build.go | 3 ++- build/url.go | 2 +- commands/util.go | 3 ++- driver/driver.go | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bake/remote.go b/bake/remote.go index 10c5d165..00a3a042 100644 --- a/bake/remote.go +++ b/bake/remote.go @@ -43,7 +43,7 @@ func ReadRemoteFiles(ctx context.Context, dis []build.DriverInfo, url string, na return nil, nil, nil } - c, err := driver.Boot(ctx, di.Driver, pw) + c, err := driver.Boot(ctx, ctx, di.Driver, pw) if err != nil { return nil, nil, err } diff --git a/build/build.go b/build/build.go index fa85ccf4..18dc2005 100644 --- a/build/build.go +++ b/build/build.go @@ -143,12 +143,13 @@ func allIndexes(l int) []int { func ensureBooted(ctx context.Context, drivers []DriverInfo, idxs []int, pw progress.Writer) ([]*client.Client, error) { clients := make([]*client.Client, len(drivers)) + baseCtx := ctx eg, ctx := errgroup.WithContext(ctx) for _, i := range idxs { func(i int) { eg.Go(func() error { - c, err := driver.Boot(ctx, drivers[i].Driver, pw) + c, err := driver.Boot(ctx, baseCtx, drivers[i].Driver, pw) if err != nil { return err } diff --git a/build/url.go b/build/url.go index 05a3da94..700e973a 100644 --- a/build/url.go +++ b/build/url.go @@ -14,7 +14,7 @@ import ( ) func createTempDockerfileFromURL(ctx context.Context, d driver.Driver, url string, pw progress.Writer) (string, error) { - c, err := driver.Boot(ctx, d, pw) + c, err := driver.Boot(ctx, ctx, d, pw) if err != nil { return "", err } diff --git a/commands/util.go b/commands/util.go index a279c659..330d8073 100644 --- a/commands/util.go +++ b/commands/util.go @@ -507,12 +507,13 @@ func boot(ctx context.Context, ngi *nginfo) (bool, error) { printer := progress.NewPrinter(context.TODO(), os.Stderr, "auto") + baseCtx := ctx eg, _ := errgroup.WithContext(ctx) for _, idx := range toBoot { func(idx int) { eg.Go(func() error { pw := progress.WithPrefix(printer, ngi.ng.Nodes[idx].Name, len(toBoot) > 1) - _, err := driver.Boot(ctx, ngi.drivers[idx].di.Driver, pw) + _, err := driver.Boot(ctx, baseCtx, ngi.drivers[idx].di.Driver, pw) if err != nil { ngi.drivers[idx].err = err } diff --git a/driver/driver.go b/driver/driver.go index 74006755..b9272a50 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -61,7 +61,7 @@ type Driver interface { Config() InitConfig } -func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, error) { +func Boot(ctx, clientContext context.Context, d Driver, pw progress.Writer) (*client.Client, error) { try := 0 for { info, err := d.Info(ctx) @@ -78,7 +78,7 @@ func Boot(ctx context.Context, d Driver, pw progress.Writer) (*client.Client, er } } - c, err := d.Client(ctx) + c, err := d.Client(clientContext) if err != nil { if errors.Cause(err) == ErrNotRunning && try <= 2 { continue