Skip to content

fix: close readiness file immediately in test goroutine#301

Open
circleci-app[bot] wants to merge 1 commit intomainfrom
chunk/changes-1778160931440-1778160931441
Open

fix: close readiness file immediately in test goroutine#301
circleci-app[bot] wants to merge 1 commit intomainfrom
chunk/changes-1778160931440-1778160931441

Conversation

@circleci-app
Copy link
Copy Markdown
Contributor

@circleci-app circleci-app Bot commented May 7, 2026

Prompt Given

Fix test-windows (30723), with failed step ./do test ./...

Root cause: The test TestOrchestrator_waitForReadiness/readiness_file_created_later was failing on Windows due to a file locking issue. The test created a file in a goroutine and registered a cleanup function with t.Cleanup() to close it. However, on Windows, the temp directory cleanup runs before the goroutine's cleanup function executes, causing the error: "The process cannot access the file because it is being used by another process."

Fix approach: Close the file immediately after creating it in the goroutine instead of deferring the cleanup. Since the test only needs the file to exist (not remain open) for the readiness check to succeed, closing it immediately resolves the race condition between the goroutine's cleanup and the test's temp directory cleanup.

Changes made:

  • Replaced t.Cleanup(func() { assert.NilError(t, f.Close()) }) with immediate assert.NilError(t, f.Close()) in the goroutine at task/orchestrator_test.go:363-364
  • This ensures the file handle is closed before the test completes and temp directory cleanup runs

Original failing job

View more about this proposed fix in the CircleCI web app →

**Root cause:** The test `TestOrchestrator_waitForReadiness/readiness_file_created_later` was failing on Windows due to a file locking issue. The test created a file in a goroutine and registered a cleanup function with `t.Cleanup()` to close it. However, on Windows, the temp directory cleanup runs before the goroutine's cleanup function executes, causing the error: "The process cannot access the file because it is being used by another process."

**Fix approach:** Close the file immediately after creating it in the goroutine instead of deferring the cleanup. Since the test only needs the file to exist (not remain open) for the readiness check to succeed, closing it immediately resolves the race condition between the goroutine's cleanup and the test's temp directory cleanup.

**Changes made:**
- Replaced `t.Cleanup(func() { assert.NilError(t, f.Close()) })` with immediate `assert.NilError(t, f.Close())` in the goroutine at task/orchestrator_test.go:363-364
- This ensures the file handle is closed before the test completes and temp directory cleanup runs
@circleci-app circleci-app Bot requested a review from a team as a code owner May 7, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants