From d350c95b04d594abedaad1846f35304b55194e84 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 27 Oct 2021 18:20:05 -0700 Subject: Replace bespoke WaitGroupErr with errgroup PiperOrigin-RevId: 406027220 --- runsc/cgroup/BUILD | 2 +- runsc/cgroup/cgroup.go | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'runsc/cgroup') diff --git a/runsc/cgroup/BUILD b/runsc/cgroup/BUILD index d3aec1fff..4dcbc285a 100644 --- a/runsc/cgroup/BUILD +++ b/runsc/cgroup/BUILD @@ -9,9 +9,9 @@ go_library( deps = [ "//pkg/cleanup", "//pkg/log", - "//pkg/sync", "@com_github_cenkalti_backoff//:go_default_library", "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", + "@org_golang_x_sync//errgroup:go_default_library", "@org_golang_x_sys//unix:go_default_library", ], ) diff --git a/runsc/cgroup/cgroup.go b/runsc/cgroup/cgroup.go index 7a0f0694f..fdcaed4ea 100644 --- a/runsc/cgroup/cgroup.go +++ b/runsc/cgroup/cgroup.go @@ -30,10 +30,10 @@ import ( "github.com/cenkalti/backoff" specs "github.com/opencontainers/runtime-spec/specs-go" + "golang.org/x/sync/errgroup" "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/cleanup" "gvisor.dev/gvisor/pkg/log" - "gvisor.dev/gvisor/pkg/sync" ) const ( @@ -412,7 +412,7 @@ func (c *Cgroup) createController(name string) (bool, error) { // existed when Install() was called, Uninstall is a noop. func (c *Cgroup) Uninstall() error { log.Debugf("Deleting cgroup %q", c.Name) - wait := sync.WaitGroupErr{} + g, ctx := errgroup.WithContext(context.Background()) for key := range controllers { if !c.Own[key] { // cgroup is managed by caller, don't touch it. @@ -423,7 +423,7 @@ func (c *Cgroup) Uninstall() error { // If we try to remove the cgroup too soon after killing the sandbox we // might get EBUSY, so we retry for a few seconds until it succeeds. - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx) fn := func() error { @@ -435,16 +435,14 @@ func (c *Cgroup) Uninstall() error { } // Run deletions in parallel to remove all directories even if there are // failures/timeouts in other directories. - wait.Add(1) - go func() { - defer wait.Done() + g.Go(func() error { if err := backoff.Retry(fn, b); err != nil { - wait.ReportError(fmt.Errorf("removing cgroup path %q: %w", path, err)) - return + return fmt.Errorf("removing cgroup path %q: %w", path, err) } - }() + return nil + }) } - return wait.Error() + return g.Wait() } // Join adds the current process to the all controllers. Returns function that -- cgit v1.2.3