summaryrefslogtreecommitdiffhomepage
path: root/runsc/cgroup
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-10-27 18:20:05 -0700
committergVisor bot <gvisor-bot@google.com>2021-10-27 18:22:30 -0700
commitd350c95b04d594abedaad1846f35304b55194e84 (patch)
tree1d0f4294b3b15c608b713ecc69ec4a3b2c34128e /runsc/cgroup
parent6078d26588c021d4b78501ad25cb725ff2db797e (diff)
Replace bespoke WaitGroupErr with errgroup
PiperOrigin-RevId: 406027220
Diffstat (limited to 'runsc/cgroup')
-rw-r--r--runsc/cgroup/BUILD2
-rw-r--r--runsc/cgroup/cgroup.go18
2 files changed, 9 insertions, 11 deletions
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