Skip to content

[wasm] Wait for killed processes and retry WBT project cleanup - #137297

Merged
maraf merged 1 commit into
mainfrom
lewing-fix-wbt-blazor-cleanup-retry
Nov 11, 2026
Merged

maraf merged 1 commit into
mainfrom
lewing-fix-wbt-blazor-cleanup-retry

Conversation

@lewing

@lewing lewing commented Nov 10, 2026

Copy link
Copy Markdown
Member

On Windows, BlazorPublishRunTest intermittently fails during SharedBuildPerTestClassFixture.RemoveDirectory because publish\wwwroot is still in use by another process.

The xharness wasm webserver runs with publish\wwwroot as its working directory. ToolCommand.Dispose() kills it with Kill(entireProcessTree: true) but never waits for it to exit. Termination is asynchronous, so the process can still hold its current-directory handle when the fixture deletes the project.

Changes:

  • ToolCommand.Dispose(): after killing the process, wait up to 30 s for it to exit (and log if it doesn't).
  • SharedBuildPerTestClassFixture.RemoveDirectory: retry IOException/UnauthorizedAccessException up to 10 times, 1 s apart, before rethrowing the existing error.

Validation: Wasm.Build.Tests compiles locally (macOS). The Windows Blazor tests weren't run locally; the failure is intermittent and only shows up on Windows.

The reported failures are on release/8.0 and release/9.0, where these files live under Common/ and 8.0 uses a taskkill-based KillTree. Manual ports will follow.

Resolves #137269

Note

This PR was generated with the assistance of GitHub Copilot.

On Windows, BlazorPublishRunTest intermittently fails in
SharedBuildPerTestClassFixture.RemoveDirectory because publish\wwwroot is
still in use. The xharness webserver runs with that directory as its working
directory, and ToolCommand.Dispose() kills it without waiting for exit, so the
handle can outlive the kill.

Wait for the killed process to exit in ToolCommand.Dispose(), and retry
transient IO/access failures when deleting build directories.

Fixes #137269

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

lewing added a commit that referenced this pull request Nov 10, 2026
…project cleanup

Port of #137297.

On Windows, BlazorPublishRunTest intermittently fails in
SharedBuildPerTestClassFixture.RemoveDirectory because publish\wwwroot is
still in use. The xharness webserver runs with that directory as its working
directory, and ToolCommand.Dispose() kills it without waiting for exit, so the
handle can outlive the kill.

Wait for the killed process to exit in ToolCommand.Dispose(), and retry
transient IO/access failures when deleting build directories.

Co-authored-by: Copilot App <[email protected]>
lewing added a commit that referenced this pull request Nov 10, 2026
…project cleanup

Port of #137297.

On Windows, BlazorPublishRunTest intermittently fails in
SharedBuildPerTestClassFixture.RemoveDirectory because publish\wwwroot is
still in use. The xharness webserver runs with that directory as its working
directory, and ToolCommand.Dispose() kills it without waiting for exit, so the
handle can outlive the kill.

Wait for the killed process to exit in ToolCommand.Dispose(), and retry
transient IO/access failures when deleting build directories.

Co-authored-by: Copilot App <[email protected]>
@lewing
lewing requested a review from steveisok November 10, 2026 22:48
@maraf

maraf commented Nov 11, 2026

Copy link
Copy Markdown
Member

/ba-g Failures are unrelated

The sole failure in build 1674053 is WBT-NoWorkload-CLR-Wasm.Build.Tests.WorkItemExecution on Windows.Server2025.Amd64.Open. Build Analysis identifies it as Helix DeadLetter, not a test assertion or project-cleanup failure. Helix reports synthetic exit code -1, no assigned machine, zero recorded execution duration, and no uploaded files; the console points to the generic dead-letter explanation.

The final Helix monitor summary accounts for all 320 work items, with only this one failing. All build jobs succeeded, including Windows and Linux Mono/CoreCLR Wasm.Build.Tests builds. The PR only adds bounded waiting after process termination and bounded directory-deletion retries; neither explains this missing Helix execution result. The precise dead-letter cause is unavailable, but there is no reported failure in the changed cleanup paths.

Note

This comment was generated with the assistance of GitHub Copilot.

@maraf
maraf merged commit b360ca6 into main Nov 11, 2026
38 of 40 checks passed
@maraf
maraf deleted the lewing-fix-wbt-blazor-cleanup-retry branch November 11, 2026 12:24
@lewing

lewing commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@lewing

lewing commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

lewing added a commit that referenced this pull request Nov 11, 2026
…project cleanup (#137298)

Fixes Issue #137269

main PR #137297

# Description

On Windows, `BlazorPublishRunTest` intermittently fails in
`SharedBuildPerTestClassFixture.RemoveDirectory` because
`publish\wwwroot` is still in use. The xharness webserver runs with that
directory as its working directory, and `ToolCommand.Dispose()` kills it
without waiting for it to exit, so the handle can outlive the kill.

This waits up to 30 s for the killed process to exit in
`ToolCommand.Dispose()`, and retries transient
`IOException`/`UnauthorizedAccessException` failures (10 attempts, 1 s
apart) when deleting build directories. Manual port: the files live
under `Common/` on this branch, and 8.0 kills via the taskkill-based
`KillTree`.

# Customer Impact

None. Test infrastructure only (Wasm.Build.Tests); reduces CI flakiness
on Windows.

# Regression

No.

# Testing

`Wasm.Build.Tests` compiles locally. The failure is intermittent and
Windows-only; CI on this PR exercises the change.

# Risk

Very low. Test-only change; no product code is affected.

# Package authoring

N/A — test infrastructure only; no package changes.

> [!NOTE]
> This PR was generated with the assistance of GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
lewing added a commit that referenced this pull request Nov 11, 2026
…project cleanup (#137299)

Fixes Issue #137269

main PR #137297

# Description

On Windows, `BlazorPublishRunTest` intermittently fails in
`SharedBuildPerTestClassFixture.RemoveDirectory` because
`publish\wwwroot` is still in use. The xharness webserver runs with that
directory as its working directory, and `ToolCommand.Dispose()` kills it
without waiting for it to exit, so the handle can outlive the kill.

This waits up to 30 s for the killed process to exit in
`ToolCommand.Dispose()`, and retries transient
`IOException`/`UnauthorizedAccessException` failures (10 attempts, 1 s
apart) when deleting build directories. Manual port: the files live
under `Common/` on this branch.

# Customer Impact

None. Test infrastructure only (Wasm.Build.Tests); reduces CI flakiness
on Windows.

# Regression

No.

# Testing

`Wasm.Build.Tests` compiles locally. The failure is intermittent and
Windows-only; CI on this PR exercises the change.

# Risk

Very low. Test-only change; no product code is affected.

> [!NOTE]
> This PR was generated with the assistance of GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
lewing added a commit that referenced this pull request Nov 11, 2026
… cleanup (#137353)

Backport of #137297 to release/10.0

/cc @lewing

## Customer Impact

- [ ] Customer reported
- [ ] Found internally

[Select one or both of the boxes. Describe how this issue impacts
customers, citing the expected and actual behaviors and scope of the
issue. If customer-reported, provide the issue number.]

## Regression

- [ ] Yes
- [ ] No

[If yes, specify when the regression was introduced. Provide the PR or
commit if known.]

## Testing

[How was the fix verified? How was the issue missed previously? What
tests were added?]

## Risk

[High/Medium/Low. Justify the indication by mentioning how risks were
measured and addressed.]

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

## Package authoring no longer needed in .NET 9

**IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

Co-authored-by: Larry Ewing <[email protected]>
Co-authored-by: Copilot App <[email protected]>
lewing added a commit that referenced this pull request Nov 11, 2026
…BuildAndPublish (#137368)

`MiscTests.MultiClientHostedBuildAndPublish` called `dotnet
build`/`publish` directly through
`DotNetCommand.ExecuteWithCapturedOutput`, without `-nr:false`. Every
other Wasm.Build.Tests build goes through
`BuildTestBase.BuildProjectWithoutAssert`, which always passes
`-nr:false`.

This PR switches the test to `BuildProjectWithoutAssert` with
`BuildOptions` or `PublishOptions`, so it gets `-nr:false` (and the
helper's binlog output fallback) from the same place as the rest of the
suite. For this test, the command line is otherwise unchanged: it runs
in the same directory (`_projectDir`) with the same `NUGET_PACKAGES`,
`-p:Configuration`, and `-bl`. The helper's `WBTOverrideRuntimePack`
path doesn't apply, because `UseWBTOverridePackTargets` is never set to
true. The binlog file name changes to the helper's convention.

## Why

Over the last 30 days (AzureDevOpsTests), this is the only
Wasm.Build.Tests test that fails with:

```
System.UnauthorizedAccessException: Access to the path 'BlazorMultiClientHosted.dll' (or '.exe') is denied
```

The failure appeared in 16 Windows `main` builds, most recently Nov 11.
The stack is `SharedBuildPerTestClassFixture.RemoveDirectory` <-
`RemoveFromCache` <- `BuildTestBase.Dispose`, so the build itself
succeeds and test cleanup fails.

**Hypothesis (not proven):** Without `-nr:false`, the build leaves
reusable MSBuild worker nodes running, and they keep the server's output
locked, so cleanup can't delete the directory. Related: #137297 added a
~9 s cleanup retry and waits for killed `ToolCommand` processes to exit.
The wait doesn't apply here, because this test never starts a
long-running process, and idle MSBuild nodes can outlive the retry
window. If this test still fails the same way after this change, the
hypothesis is wrong.

## Related cleanup

While doing this, we found that `BuildProjectWithoutAssert` discards the
result of LINQ `Append` when it tries to add
`-p:WasmBuildOnlyAfterPublish=true`, so
`PublishOptions.BuildOnlyAfterPublish` never took effect. That's
harmless: `dotnet publish` already defaults
`WasmBuildOnlyAfterPublish=true`. #137370 removes the dead code
separately.

## Validation

Not built or run locally. I skipped the SDK bootstrap and
Wasm.Build.Tests dependency build to save disk space. CI will compile it
and run the test.

> [!NOTE]
> This PR description and change were generated with GitHub Copilot.

---------

Co-authored-by: Copilot App <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 11, 2026
lewing added a commit that referenced this pull request Nov 16, 2026
… cleanup (#137352)

Backport of #137297 to release/11.0

/cc @lewing

## Customer Impact

- [ ] Customer reported
- [ ] Found internally

[Select one or both of the boxes. Describe how this issue impacts
customers, citing the expected and actual behaviors and scope of the
issue. If customer-reported, provide the issue number.]

## Regression

- [ ] Yes
- [ ] No

[If yes, specify when the regression was introduced. Provide the PR or
commit if known.]

## Testing

[How was the fix verified? How was the issue missed previously? What
tests were added?]

## Risk

[High/Medium/Low. Justify the indication by mentioning how risks were
measured and addressed.]

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

## Package authoring no longer needed in .NET 9

**IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

Co-authored-by: Larry Ewing <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[9.0][8.0][wasm] BlazorPublishRunTest fails deleting a directory in use

2 participants