microsoft / microsoft/playwright-dotnet
[BUG] Rebuild or clean fails with <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3k
- Forks
- 304
- Avg merge
- 20h 47m
- Merged PRs (30d)
- 6
Description
Context:
- Playwright Version: 1.18.0
- Operating System: Windows 10 21H2
- .NET version: .NET 5, .NET 6
- Browser: N/A, happens at build time
Code Snippet
See https://github.com/davidjnet/playwright-build-race for a full repro.
Run dotnet build then dotnet build -t:Rebuild
Multiple projects proj-a, proj-B, proj-c, ... all depend on a common library common-lib. Common-lib in turn depends on Playwright.
The projects all build their output to the same directory and have <UseCommonOutputDirectory>true</UseCommonOutputDirectory>. (In the sample repo, this is set in Directory.Build.props so it applies to all projects in the tree.)
Describe the bug
Several projects are rebuilding in parallel to the same output directory and they all have a transitive dependency on the Microsoft.Playwright nuget package. src/Playwright/build/Microsoft.Playwright.targets defines a PlaywrightBuildCleanup target which deletes the .playwright directory. Because several projects run this at once, there is a race condition where they all try to recursively enumerate & delete the contents of .playwright at the same time. They error because multiple projects are trying to delete the same files at the same time; or because one project has a directory open to enumerate it while another project is trying to delete the directory.
Example error:
C:\Users\David.James\.nuget\packages\microsoft.playwright\1.18.0\buildTransitive\Microsoft.Playwright.targets(33,5): error MSB3231: Unable to remove directory "C:\git\playwright-build-race\\common-bin\net6.0\\.playwright". Access to the path '\\?\C:\git\playwright-build-race\common-bin\net6.0\.playwright\package\lib\third_party\highlightjs\highlightjs' is denied. [C:\git\playwright-build-race\proj-d\proj-d.csproj]
C:\Users\David.James\.nuget\packages\microsoft.playwright\1.18.0\buildTransitive\Microsoft.Playwright.targets(33,5): error MSB3231: Unable to remove directory "C:\git\playwright-build-race\\common-bin\net6.0\\.playwright". Access to the path '\\?\C:\git\playwright-build-race\common-bin\net6.0\.playwright\package\lib\third_party\highlightjs\highlightjs' is denied. [C:\git\playwright-build-race\proj-b\proj-b.csproj]
C:\Users\David.James\.nuget\packages\microsoft.playwright\1.18.0\buildTransitive\Microsoft.Playwright.targets(33,5): error MSB3231: Unable to remove directory "C:\git\playwright-build-race\\common-bin\net6.0\\.playwright". Access to the path '\\?\C:\git\playwright-build-race\common-bin\net6.0\.playwright\package\lib\webpack' is denied. [C:\git\playwright-build-race\proj-c\proj-c.csproj]```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/Playwright/build/Microsoft.Playwright.targets, especially the PlaywrightBuildCleanup target at the reported line, and reproduce the issue with the linked repro using dotnet build followed by dotnet build -t:Rebuild. Trace how the cleanup runs for projects sharing the output directory. Done means parallel rebuilds no longer fail while cleaning the shared .playwright directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100