fix: close readiness file immediately in test goroutine#301
Open
circleci-app[bot] wants to merge 1 commit intomainfrom
Open
fix: close readiness file immediately in test goroutine#301circleci-app[bot] wants to merge 1 commit intomainfrom
circleci-app[bot] wants to merge 1 commit intomainfrom
Conversation
**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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prompt Given
Fix test-windows (30723), with failed step ./do test ./...
Root cause: The test
TestOrchestrator_waitForReadiness/readiness_file_created_laterwas failing on Windows due to a file locking issue. The test created a file in a goroutine and registered a cleanup function witht.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:
t.Cleanup(func() { assert.NilError(t, f.Close()) })with immediateassert.NilError(t, f.Close())in the goroutine at task/orchestrator_test.go:363-364Original failing job
View more about this proposed fix in the CircleCI web app →