Repository navigation
Perform inner repo clean-up asynchronously - #8168
Merged
Merged
Conversation
The CleanupRepo target deleted the repo's artifacts dir synchronously as part of the repo wrapper project's build, so every dependent repo waited for that deletion to finish before it could start building. The artifacts dir is isolated to the repo that produced it and nothing else reads from it, so there is no reason for the P2P protocol to wait on it. Spawn the deletion as a detached background process instead. Redirecting all three standard streams is required rather than cosmetic: Exec waits on the pipes it hands out, so a detached process that inherits them keeps Exec blocked for the full deletion. Measured against an 8s command, the Exec call returns in 654ms instead of 8793ms on Windows and 125ms instead of 8242ms on Unix; without the redirection it still takes the full 8.7s. Also: - Remove the build server shutdown. It was only needed back when a failed clean operation failed the build, which is no longer the case. This also makes the source-build hang workaround for dotnet/source-build#4796 unnecessary. - Remove the Inputs/Outputs/Touch incrementality. The target's existing Exists(RepoArtifactsDir) condition already expresses whether cleanup is needed, and it does so more truthfully than a stamp file that would be written before the detached deletion completes. - Remove the 'DirSize After CleanupRepo' measurement. With the deletion running in the background it races the other repos and no longer measures anything meaningful. Deletion failures are no longer observable through the build, so stderr is captured in artifacts/log/<repo>/CleanupRepo.log. The log is empty on success. Fixes #8167 Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the VMR repo-wrapper build orchestration so that per-inner-repo artifact cleanup no longer blocks downstream repo builds, improving parallel build performance by running cleanup as a detached background process.
Changes:
- Run
CleanupRepodeletion of$(RepoArtifactsDir)asynchronously via a detached process (Windows:start /B; Unix:nohup … &) with stream redirection to avoidExecblocking. - Remove the build server shutdown step and related timeout properties from the cleanup path.
- Remove incremental/stamp-based cleanup bookkeeping (
Inputs/Outputs,CleanupRepo.complete) and the post-cleanup disk usage measurement.
Show a summary per file
| File | Description |
|---|---|
| repo-projects/Directory.Build.targets | Detaches CleanupRepo artifact deletion (with redirected streams) to avoid blocking dependent repos during project-to-project builds. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
mmitche
reviewed
Aug 6, 2026
mmitche
reviewed
Aug 6, 2026
start /B doesn't detach: cmd gives the spawned process an inheritable copy of Exec's stdout/stderr pipes, so Exec waited for the full delete anyway. Measured with an 8s command under Exec: start /B 9587ms vs 9488ms synchronous, i.e. no gain. Start-Process uses ShellExecute, which doesn't inherit handles: 2006ms, and the delete still runs to completion. Redirection is still needed on Unix to close the inherited pipes (188ms vs 8203ms without), but it doesn't need to go to a file. Since a failed delete is best effort and nothing consumes the output, redirect to /dev/null and stop producing and publishing an empty CleanupRepo.log. Co-authored-by: Copilot <[email protected]> Copilot-Session: 8df1e800-36c4-4797-b8d7-d2c8e23c1342
Member
Author
|
/azp run dotnet-unified-build-full |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
akoeplinger
approved these changes
Aug 7, 2026
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.
Fixes #8167.
CleanupRepodeleted the repo's artifacts dir synchronously as part of the repo wrapper project's build, so every dependent repo waited for that deletion before it could start building. The artifacts dir is isolated to the repo that produced it and nothing else reads from it, so there's no reason for the P2P protocol to wait on it.It's now spawned as a detached background process.
Why detaching is subtle
Execdoesn't just wait on the process it launches, it waits until the stdout/stderr pipes it handed out are closed. Any child that ends up holding a copy of those pipes keepsExecblocked for the full deletion.On Windows
start /Bdoesn't achieve this:cmdgives the spawned process an inheritable copy of those pipes, soExecwaits for the whole delete even thoughstartitself returns in ~30 ms. Redirecting the streams doesn't change that.Start-Processgoes throughShellExecute, which doesn't inherit handles, soExecis released immediately.On Unix
nohup ... &does detach, but only if the streams are redirected —</dev/nulland>/dev/nullare load-bearing rather than cosmetic.Measured by timing a complete MSBuild invocation against an 8s command:
start /B, redirected to a filestart /B, redirected toNUL/dev/nullStart-Process -WindowStyle HiddenThe Windows figure is dominated by
powershellstart-up. Each case was also checked against a real directory to confirm the deletion actually ran to completion rather than being silently dropped.No clean-up log
Nothing consumes the output and the deletion is best effort, so both platforms redirect to the null device and no
CleanupRepo.logis produced or published. On Unix such a log would always be empty regardless: POSIX unlinks directory entries even when handles are open, sorm -rfdoesn't fail on locked files.Also removed
BuildServerShutdownTimeout*properties, which had no other consumers.Inputs/Outputs/MakeDir/TouchExists('$(RepoArtifactsDir)')condition already expresses whether cleanup is needed, and more truthfully than a stamp written before the detached deletion completes. Nothing else readCleanupRepo.complete.DirSize After CleanupRepoDirSize Before BuildingandDirSize After Buildingare unchanged and still go to the console.Behaviour changes worth knowing
rmdirskip that file and its whole parent chain, so some space silently isn't reclaimed. The build still succeeds and nothing reports it.&ignoreSIGINTin non-interactive shells, so the deletion runs to completion either way. This is benign — the space still gets freed and the artifacts are garbage after a cancel — but restarting a build immediately after cancelling can race an in-flight deletion.CleanWhileBuildingis opt-in (--clean-while-building) and predominantly used in CI, where cancellation kills the agent anyway.Validation
dotnet msbuild repo-projects\roslyn.proj -getProperty:RepoArtifactsDirevaluates cleanly.BuildServerShutdown*orCleanupRepo.completeoutsidesrc/.Execreturns immediately, that the deletion completes afterwards, and that the detached process outlives its parent shell.conhostand windowed-process counts unchanged) and noTerminate batch job (Y/N)?prompt — the detached command iscmd /c rmdir, an internal command rather than a batch file.Note
This pull request description was generated with GitHub Copilot.