coverlet: Could not write lines to file CoverletSourceRootsMapping - in use by another process

Our build process with coverlet > 3.0 tends to fail with an error like this:

C:\Users\VssAdministrator\.nuget\packages\coverlet.collector\3.0.4-preview.25\build\netstandard1.0\coverlet.collector.targets(48,5): error MSB3491: Could not write lines to file "..\..\_tests\net5.0\linux-musl-arm64\CoverletSourceRootsMapping". The process cannot access the file 'D:\a\1\s\_tests\net5.0\linux-musl-arm64\CoverletSourceRootsMapping' because it is being used by another process. [D:\a\1\s\src\NzbDrone.Host.Test\Radarr.Host.Test.csproj]
  Radarr.Windows.Test -> D:\a\1\s\_tests\net5.0\linux-musl-x64\publish\

I suspect this is because we have a centralized output directory (not one per project).

  <PropertyGroup>
    <!-- Output to _output and _tests respectively -->
    <OutputPath Condition="'$(RadarrProject)'=='true'">$(RadarrRootDir)_output\</OutputPath>
    <OutputPath Condition="'$(RadarrOutputType)'=='Test'">$(RadarrRootDir)_tests\</OutputPath>
  </PropertyGroup>

Can this be worked around at all?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 33

Commits related to this issue

Most upvoted comments

This fix is not yet merged…I’m having some hassle on tests and I’m a bit busy, I’ll try to work on it asap.

Not yet, I’m having issue with this fix in CI…I need to investigate a bit more.

Hello!

Any development on this subject? It seems since we migrated to .net6, the bug occurs almost always. We did not have the problem before that.

Hi all,

I’ve published a test package here https://f.feedz.io/marcorossignoli/coverletunofficial/nuget/index.json the versions are

coverlet.collector 3.1.3-preview.7.gb1603b798b coverlet.msbuild 3.1.3-preview.7.gb1603b798b

I need help, can someone give it a try and let me know if it’s working?

Hello!

Any development on this subject? It seems since we migrated to .net6, the bug occurs almost always. We did not have the problem before that.

Yes, we observe the same - 85% chance of error, prior to net6 we haven’t seen this error.

I’ve started to work on this one the idea is to create the file mapping using some sort of hash for the “current” test container to avoid collision in case of solutions with more containers in the same output folder. Something like image Let’s see it it can work…there’re some place to change:

  • targets msbuild/collectors
  • SourceRootTranslator
  • Tests

cc: @daveMueller

We have the same issue, basically the scenario is:

  • a solution with multiple test projects
  • output to the same folder
  • build the solution (with msbuild /m to enable msbuild concurrency)

Since this is a “build timing” bug related to writing to the same file, it is not 100% reproducable.

However, I think a good fix would probably be to append or prefix the MSBuildProjectName to the CoverletSourceRootsMapping file, e.g.

_sourceRootMappingFilePath: “$([MSBuild]::EnsureTrailingSlash(‘$(OutputPath)’))CoverletSourceRootsMapping -$(MSBuildProjectName)

This will ensure that the CoverletSourceRootsMapping file is unique per MSBuildProject (i.e. per Assembly)

Same problem here. Build with single process with a solution >50 projects is not an option.

Yes, a CoverletSourceRootsMapping_dlltestname.Tests file was created for every test project in the solution.

thanks @bretthysuik can you confirm that in you output folder you see a list of CoverletSourceRootsMapping_dlltestname?

Can someone else give a try to coverlet.msbuild 3.1.3-preview.7.gb1603b798b?

It’s on high priority, but didn’t have time to work on it yet, bit busy times.

Can someone provide a repro to speedups a bit the analysis?

Coverlet is open source if someone wants to take this one I’m glad to review and help. In case let me know that I’ll assign the issue to avoid to accidentally waste time.

For now a possible solutions could be update coverlet to write the mapping in a folder like $(OutputPath)\CoverletSourceMappings\CoverletSourceRootsMapping_{Guid}` and merge/use when needed.

Ah, that’s what I was afraid of. I’m working on a project with 60 test projects… I actually ended up upgrading Microsoft.NET.Test.Sdk, MSTest.TestAdapter, and MSTest.TestFramework to their latest versions since we were way behind and all issues seem to have gone away. Tried looking in the changelogs for each of these to see if some sort of race-condition was fixed but didn’t spot any specifically. Either way, for future peeps stumbling on this problem, there’s a few fixes in this thread now. Thanks again @LevYas!