From a1cd19aa020522bd6d16ee8ec5f9318932b7126a Mon Sep 17 00:00:00 2001 From: Snider Date: Wed, 4 Feb 2026 12:53:44 +0000 Subject: [PATCH] fix(container): check context before select in Stop to fix flaky test Stop() now checks ctx.Err() before entering the select block. When a pre-cancelled context is passed, the select could non-deterministically choose <-done over <-ctx.Done() if the process had already exited, causing TestLinuxKitManager_Stop_Good_ContextCancelled to fail on CI. Co-Authored-By: Claude Opus 4.5 --- pkg/container/linuxkit.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/container/linuxkit.go b/pkg/container/linuxkit.go index ee203b4..2f2780a 100644 --- a/pkg/container/linuxkit.go +++ b/pkg/container/linuxkit.go @@ -258,6 +258,12 @@ func (m *LinuxKitManager) Stop(ctx context.Context, id string) error { return nil } + // Honour already-cancelled contexts before waiting + if err := ctx.Err(); err != nil { + _ = process.Signal(syscall.SIGKILL) + return err + } + // Wait for graceful shutdown with timeout done := make(chan struct{}) go func() {