diff --git a/cmd/containerd-shim-lcow-v2/manager.go b/cmd/containerd-shim-lcow-v2/manager.go index 6ab22af109..a05aa16070 100644 --- a/cmd/containerd-shim-lcow-v2/manager.go +++ b/cmd/containerd-shim-lcow-v2/manager.go @@ -183,8 +183,8 @@ func (m *shimManager) Start(ctx context.Context, id string, opts shim.StartOpts) // It reads and logs any panic messages written to panic.log, then tries to // terminate the associated HCS compute system and waits up to 30 seconds for // it to exit. -func (m *shimManager) Stop(_ context.Context, id string) (resp shim.StopStatus, err error) { - ctx, span := ot.StartSpan(context.Background(), "delete") +func (m *shimManager) Stop(ctx context.Context, id string) (resp shim.StopStatus, err error) { + ctx, span := ot.StartSpan(ctx, "delete") defer span.End() defer func() { ot.SetSpanStatus(span, err) }() diff --git a/cmd/containerd-shim-lcow-v2/manager_test.go b/cmd/containerd-shim-lcow-v2/manager_test.go index c080040233..252fd88045 100644 --- a/cmd/containerd-shim-lcow-v2/manager_test.go +++ b/cmd/containerd-shim-lcow-v2/manager_test.go @@ -3,11 +3,29 @@ package main import ( + "context" "os" "path/filepath" "testing" + + "github.com/Microsoft/hcsshim/internal/shim" ) +func TestStopPreservesShimOptionsContext(t *testing.T) { + ctx := context.WithValue(t.Context(), shim.OptsKey{}, shim.Opts{BundlePath: t.TempDir()}) + + status, err := newShimManager("test").Stop(ctx, "nonexistent-stop-context-test") + if err != nil { + t.Fatalf("Stop: %v", err) + } + if status.ExitStatus != 255 { + t.Fatalf("ExitStatus = %d, want 255", status.ExitStatus) + } + if status.ExitedAt.IsZero() { + t.Fatal("ExitedAt is zero") + } +} + // TestLimitedRead verifies that limitedRead correctly enforces the byte limit // when the file is larger than the limit, and reads the full content when the // file is smaller than the limit.