Use backoff to tolerant race condition.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
8ec51bb848
commit
d5ee05fc25
@ -20,7 +20,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/errdefs"
|
||||||
cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs"
|
cgroupfs "github.com/opencontainers/runc/libcontainer/cgroups/fs"
|
||||||
libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs"
|
libcontainerconfigs "github.com/opencontainers/runc/libcontainer/configs"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
@ -91,10 +93,28 @@ func newContainerdContainerHandler(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
taskPid, err := client.TaskPid(ctx, id)
|
// Cgroup is created during task creation. When cadvisor sees the cgroup,
|
||||||
if err != nil {
|
// task may not be fully created yet. Use a retry+backoff to tolerant the
|
||||||
return nil, err
|
// race condition.
|
||||||
|
// TODO(random-liu): Use cri-containerd client to talk with cri-containerd
|
||||||
|
// instead. cri-containerd has some internal synchronization to make sure
|
||||||
|
// `ContainerStatus` only returns result after `StartContainer` finishes.
|
||||||
|
var taskPid uint32
|
||||||
|
backoff := 100 * time.Millisecond
|
||||||
|
retry := 5
|
||||||
|
for {
|
||||||
|
taskPid, err = client.TaskPid(ctx, id)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
retry--
|
||||||
|
if !errdefs.IsNotFound(err) || retry == 0 {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
time.Sleep(backoff)
|
||||||
|
backoff *= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
rootfs := "/"
|
rootfs := "/"
|
||||||
if !inHostNamespace {
|
if !inHostNamespace {
|
||||||
rootfs = "/rootfs"
|
rootfs = "/rootfs"
|
||||||
|
Loading…
Reference in New Issue
Block a user