Skip to content

fix(test): cancel watchSandbox goroutine to prevent flaky TempDir cleanup race #1439

Description

@ptone

Problem

TestCloudRunSandboxRuntime_Run_BuildsCommand in pkg/runtime has a race condition:
Run() starts a background watchSandbox goroutine that writes to a state file in
t.TempDir(). When the test ends, t.TempDir() cleanup (RemoveAll) races with the
goroutine's writes, causing intermittent "directory not empty" failures on CI.

This has been independently discovered and fixed twice on different branches:

Fix

Add a t.Cleanup() call after Run() returns to cancel the watcher goroutine
before TempDir cleanup fires (t.Cleanup is LIFO, so a cleanup registered after
Run fires before the TempDir RemoveAll).

Files Modified

  • pkg/runtime/cloudrun_sandbox_runtime_test.go (test-only change)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions