Skip to content

Retry deleting smoke test work folders on Windows - #2188

Open
waldekmastykarz wants to merge 3 commits into
dotnet:mainfrom
waldekmastykarz:fix-stdio-test-cleanup-windows
Open

waldekmastykarz wants to merge 3 commits into
dotnet:mainfrom
waldekmastykarz:fix-stdio-test-cleanup-windows

Conversation

@waldekmastykarz

Copy link
Copy Markdown
Collaborator

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 8e9fd844c707b4cbded9ea7d605b99fa3b6b5655

Dimension Assessment Rationale
Change confidence 8.5/10 ↑ Test-only change; build clean and all 11 ProcessSmokeTests pass on macOS.
↓ The Windows race isn't reproducible locally; only CI over time confirms the flake is gone.
Diagnosis confidence 8/10 ↑ The exception comes from deleting the top-level folder (RemoveDirectoryInternal), consistent with a process still using it as its working directory.
↓ Which process held it (the dotnet host or the cmd.exe/more child) wasn't captured.
Evidence fit 8/10 ↑ Same failure in cleanup after the assertions passed, Windows only, on two unrelated branches (#2152 and fix-2139-cert-prompt-json); a rerun passed.

Fixes an intermittent Windows failure in ProcessSmokeTests.Stdio_BackToBackJsonRpcMessages_AreMockedIndividually:

System.IO.IOException : The process cannot access the file '\\?\C:\Users\runneradmin\AppData\Local\Temp\devproxy-stdio-zoqjwaxx.dlp' because it is being used by another process.
   at System.IO.FileSystem.RemoveDirectoryInternal(...)
   at System.IO.DirectoryInfo.Delete(Boolean recursive)

The test's assertions pass. The failure happens in finally when deleting the work folder. StopHost kills the whole process tree but can only wait for the dotnet host. On Windows, the killed descendants (cmd.exe /c more), whose working directory is the work folder, can still be shutting down when the delete runs.

Changes

  • Add DeleteWorkDir, which retries the delete on IOException/UnauthorizedAccessException for up to 10 seconds, and use it for every work folder cleanup in ProcessSmokeTests.

A killed host's descendants (cmd.exe /c more in the stdio tests) can still
hold the work folder as their working directory right after Kill returns,
which made Stdio_BackToBackJsonRpcMessages_AreMockedIndividually fail
intermittently on Windows.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@waldekmastykarz
waldekmastykarz requested a review from a team as a code owner November 26, 2026 14:16
Copilot AI balanced review requested due to automatic review settings November 26, 2026 14:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the temporary work-directory cleanup retry change.

No open issues 🎉

What changed in this PR

This PR addresses intermittent Windows failures in Dev Proxy’s process smoke tests by allowing time for terminated processes to release temporary working directories.

Changes:

  • Adds DeleteWorkDir, which retries deletion on I/O or access errors for up to 10 seconds.
  • Uses the helper at all five work-directory cleanup sites in ProcessSmokeTests.
File Description
DevProxy.Integration.Tests/​ProcessSmokeTests.cs Adds bounded deletion retries and applies them consistently to temporary work-directory cleanup.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the retry-based smoke-test cleanup changes.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional test results

  • PR: dotnet/dev-proxy#2188
  • Tested commit: ea2a3c28409ca2ec24e2b75902f8f2b06409497c
  • Environment: macOS 27.2.1, .NET SDK 10.0.103. Dedicated worktree and fixture home; both HOME and CFFIXED_USER_HOME isolated; certificate installation and system-proxy registration disabled.
Scenario or test command Expected Actual Result
dotnet restore DevProxy.sln --locked-mode; build DevProxy.Integration.Tests and DevProxy with --no-restore Exact-head source builds without errors Both builds: 0 warnings, 0 errors. Initial no-restore attempt lacked assets; locked restore resolved it. PASS
Invoke compiled ProcessSmokeTests.DeleteWorkDir by reflection on a populated directory, then the same absent directory Recursive removal; absent directory returns immediately Removed in 5 ms; absent directory returned in 0 ms. No repository tests rerun locally. PASS
Deny write access on an owned directory's parent, confirm direct deletion fails, restore access after 650 ms, invoke actual compiled helper Retry succeeds after access is restored Directory removed after 735 ms. This exercises a real filesystem failure, not a mocked exception. PASS
Keep parent write access denied while invoking actual compiled helper Retry for approximately 10 seconds, then surface failure rather than silently succeed IOException surfaced after 10,064 ms; directory remained until fixture permissions were restored. PASS
Start source-built host with --detach --as-system-proxy false --port 0 --api-port 0 --install-cert false --no-first-run; PID-scoped status; authenticated GET /proxy; explicit proxy request to http://api.contoso.local/hello Detached process stays alive, API responds, configured mock is served Owned PID 15381; API http://127.0.0.1:57883 returned 200; proxy port 57882 returned 200 with exact body hello from the mock. State, certificate, token and logs remained under the owned fixture home. PASS
devproxy stop --pid 15381 using matching source build Owned process exits gracefully Exit verified; fixture files removed afterward. PASS
Current-head automated validation, inspected rather than rerun CI passes for tested SHA CI run is successful for the tested commit. Windows log: 289 unit tests passed; 299 integration tests passed, 2 skipped. macOS, Ubuntu, build, client smoke and CodeQL checks also report success. PASS
Reproduce Windows descendant-held working-directory lock and prove eventual release during retry Original Windows cleanup race recovers No Windows execution host available in this session. macOS permission probes cover retry and timeout behavior but do not reproduce Windows directory-handle semantics; a green Windows CI run does not demonstrate that this intermittent race was exercised. BLOCKED

Requested changes

None.

Outcome

Comment only: observed helper behavior and the adjacent runtime smoke scenario pass, with no reproduced functional defect attributable to this PR. Direct validation of the Windows-specific race remains blocked, so this is not an approval or a change request.

Cleanup complete: only owned PIDs were touched; fixture state, certificates, tokens, logs and temporary files were removed; tracked source remained unchanged. An initial harness invocation incorrectly passed --config-file to status and stop; its owned PID 14199 required SIGTERM and its exit was verified. Correcting those harness arguments produced the successful graceful-shutdown result above. The first isolated probe compilation also hit an empty-cache NuGet/TLS error; rerunning the probe compilation with the existing SDK/package cache succeeded. These setup issues were not PR defects.

Copilot AI balanced review requested due to automatic review settings November 27, 2026 08:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues for the temporary-directory cleanup retry changes.

No open issues 🎉

Review effort: Balanced

@garrytrinder garrytrinder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional test results

  • PR: dotnet/dev-proxy#2188
  • Tested commit: 1d81c5be96410647618cfe87ef39f6c78a96ce9c
  • Environment: macOS 27.2.1, .NET SDK 10.0.103; retest on November 27. Latest upstream head checked out in the dedicated clean worktree. Runtime fixtures use isolated HOME and CFFIXED_USER_HOME, pre-created Library/Application Support, and their own certificate path. No system-proxy changes or certificate trust installation.

The latest head merges updated main; the net PR diff remains one file, and the cleanup helper is unchanged. The results below are newly executed against the latest head, not carried forward from the earlier review.

Scenario or test command Expected Actual Result
dotnet restore DevProxy.sln --locked-mode; build DevProxy.Integration.Tests and DevProxy with --no-restore Latest-head source builds cleanly Both builds succeeded with 0 warnings and 0 errors. No tracked dependency files changed. PASS
Invoke actual compiled ProcessSmokeTests.DeleteWorkDir by reflection on a populated directory, then the now-missing directory Recursive removal; absent directory returns immediately Removal in 9 ms; absent-directory return in 0 ms. PASS
Remove write permission on an owned parent directory; confirm direct deletion fails; restore permission after 650 ms; invoke compiled helper Retries until access is restored, then removes the directory Real filesystem failure recovered; directory removed after 844 ms. PASS
Leave parent write permission denied while invoking compiled helper Approximately 10-second retry deadline; failure surfaces rather than being swallowed IOException surfaced after 10,042 ms; directory remained until fixture permissions were restored. PASS
Source-built host: --detach --as-system-proxy false --port 0 --api-port 0 --install-cert false --no-first-run --output json --config-file <owned-config>; PID-scoped status and authenticated GET /proxy Detached process stays alive and API responds Owned PID 42217; assigned API http://127.0.0.1:53303 returned HTTP 200 with a JSON object. PASS
Explicit HTTP proxy request through assigned port 53302 to http://api.contoso.local/hello Config-loaded mock returns HTTP 200 and exact body HTTP 200, exact body hello from the mock. Isolated state, token, certificate and logs verified inside the owned fixture home. PASS
Matching source build devproxy stop --pid 42217 Graceful shutdown, owned process exits Stop succeeded and process exit was verified. PASS
Inspect actual Windows CI log for the tested head; do not rerun automated suites locally Current-head automated suites succeed, skips disclosed CI run 45968009574 confirms exact tested SHA. Windows job log: 171 abstractions, 227 Kestrel, 358 host and 445 integration tests passed; 2 integration tests skipped (Startup_EnvironmentOverrides... and Status_HonorsInstanceTokenSuppression...). No failed tests. Current-head macOS, Ubuntu, build, client smoke and CodeQL checks also pass. PASS
Reproduce the Windows descendant-held working-directory lock and observe recovery during retry Original Windows race demonstrated and fixed No Windows execution host is available to this session. macOS permission failures exercise retry and timeout behavior, not Windows descendant directory-handle behavior. The successful Windows CI run does not prove that the intermittent race was exercised. BLOCKED

Requested changes

None.

Outcome

Comment only. All executed probes and adjacent runtime scenarios pass on the latest head, with no reproduced PR-attributable defect. The essential direct Windows race reproduction remains blocked, so the evidence does not justify approval or a change request.

Cleanup complete: owned PID 42217 exited gracefully; temporary fixtures, certificate, token, state and logs were removed. Original branch checkout restored and tracked/untracked worktree clean. No fixes, commits, pushes or merges. The standalone reflection harness emitted analyzer warnings while compiling; the repository builds themselves were warning-free.

This branch has not been deployed

No deployments
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.

3 participants