From 0b97695007550ef726305100675b36e25412f20f Mon Sep 17 00:00:00 2001 From: ningmingxiao Date: Mon, 17 Mar 2025 17:09:47 +0800 Subject: [PATCH] fix:nerdctl ps show nothing when timeout Signed-off-by: ningmingxiao --- cmd/nerdctl/compose/compose_ps.go | 5 ----- pkg/containerutil/containerutil.go | 4 ---- pkg/formatter/formatter.go | 4 ---- 3 files changed, 13 deletions(-) diff --git a/cmd/nerdctl/compose/compose_ps.go b/cmd/nerdctl/compose/compose_ps.go index c3ea4fd2578..badee1755b9 100644 --- a/cmd/nerdctl/compose/compose_ps.go +++ b/cmd/nerdctl/compose/compose_ps.go @@ -21,7 +21,6 @@ import ( "fmt" "strings" "text/tabwriter" - "time" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -345,10 +344,6 @@ func formatPublishers(labelMap map[string]string) []PortPublisher { // statusForFilter returns the status value to be matched with the 'status' filter func statusForFilter(ctx context.Context, c containerd.Container) string { - // Just in case, there is something wrong in server. - ctx, cancel := context.WithTimeout(ctx, 5*time.Second) - defer cancel() - task, err := c.Task(ctx, nil) if err != nil { // NOTE: NotFound doesn't mean that container hasn't started. diff --git a/pkg/containerutil/containerutil.go b/pkg/containerutil/containerutil.go index c929a1716c4..1e4fe2a34e3 100644 --- a/pkg/containerutil/containerutil.go +++ b/pkg/containerutil/containerutil.go @@ -86,10 +86,6 @@ func PrintHostPort(ctx context.Context, writer io.Writer, container containerd.C // ContainerStatus returns the container's status from its task. func ContainerStatus(ctx context.Context, c containerd.Container) (containerd.Status, error) { - // Just in case, there is something wrong in server. - ctx, cancel := context.WithTimeout(ctx, 5*time.Second) - defer cancel() - task, err := c.Task(ctx, nil) if err != nil { return containerd.Status{}, err diff --git a/pkg/formatter/formatter.go b/pkg/formatter/formatter.go index 1c6acdcfced..3801e1ab208 100644 --- a/pkg/formatter/formatter.go +++ b/pkg/formatter/formatter.go @@ -39,11 +39,7 @@ import ( ) func ContainerStatus(ctx context.Context, c containerd.Container) string { - // Just in case, there is something wrong in server. - ctx, cancel := context.WithTimeout(ctx, 5*time.Second) - defer cancel() titleCaser := cases.Title(language.English) - task, err := c.Task(ctx, nil) if err != nil { // NOTE: NotFound doesn't mean that container hasn't started.