Skip to content

Retry test cleanup while Windows still locks dotnet.exe - #744

Merged
mmitche merged 4 commits into
dotnet:mainfrom
akirayamamoto:fix/windows-test-cleanup-retry
Nov 4, 2026
Merged

mmitche merged 4 commits into
dotnet:mainfrom
akirayamamoto:fix/windows-test-cleanup-retry

Conversation

@akirayamamoto

Copy link
Copy Markdown
Contributor

Why

Windows CI sometimes fails a test that actually passed, during cleanup:

System.Exception : Failed to remove C:\Users\cloudtest\AppData\Local\Temp\InstallScript-Tests\5gd5sltz.wbx
---- System.UnauthorizedAccessException : Access to the path 'dotnet.exe' is denied.

Seen in #659 and again on #743 (WhenInstallingASpecificVersionOfDotnetRuntime, 7.0.0-alpha). #660 made the error visible but didn't stop it.

Root cause

Each test runs dotnet --info from its install folder, then Dispose() deletes that folder. Windows can keep dotnet.exe locked for a moment after the process exits (for example while antivirus scans it), so the first delete attempt can fail.

Approach

  • Moved the cleanup into TestUtils.DeleteInstallationDirectory.
  • It retries the delete on UnauthorizedAccessException or IOException (file in use), up to 8 attempts. The wait doubles from 100 ms and is capped at 1 s, so it gives up after about 4.5 s. Then it throws the same "Failed to remove" error as before.
  • A missing folder is still ignored, as before.

Validation

I reproduced the failure on a Windows GitHub Actions runner in my fork with a temporary test that deletes the folder while a copied executable is still running from it:

  • Without the retry: fails with the same Access to the path 'dotnet.exe' is denied error.
  • With the retry: passes.

I left that test out of this PR, since the suite doesn't test its own helpers.

Follow-up to #659

🤖 Generated with Claude Code

akirayamamoto and others added 4 commits October 23, 2026 15:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@akirayamamoto

Copy link
Copy Markdown
Contributor Author

Hi @ellahathaway and @MichaelSimons, this one is small and CI is green.

It retries the test folder cleanup when Windows still has dotnet.exe locked, which is the flaky failure blocking #743 (fix "Killed: 9" on macOS). Merging this first should get #743 green too.

Thanks!

@MichaelSimons

Copy link
Copy Markdown
Member

Hi @ellahathaway and @MichaelSimons, this one is small and CI is green.

It retries the test folder cleanup when Windows still has dotnet.exe locked, which is the flaky failure blocking #743 (fix "Killed: 9" on macOS). Merging this first should get #743 green too.

Thanks!

@akirayamamoto , thanks for your contribution. @dotnet/install-scripts-maintainers is the team to ping for approval or other questions. @ellahathaway and myself, are focusing in different areas at the moment.

@mmitche
mmitche merged commit ee83f9c into dotnet:main Nov 4, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Rollout in .NET Install Scripts Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Rollout

Development

Successfully merging this pull request may close these issues.

3 participants