roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Open files in packages directory remain locked after a build

Open nickdurcholz opened this issue 7 years ago • 2 comments

Version Used: 2.10.0

Steps to Reproduce: Build any MVC application

Expected Behavior: After msbuild exits, no files in packages\Microsoft.Net.Compilers.2.10.0 remain locked.

Actual Behavior: The files are locked

On our CI server, we are having builds fail because our build system (Team City) reuses worksapces that were used for a previous build, does a git clean -xdf at the start of the build, and VBCSCompiler.exe is still running from the last build. Here is some sample output showing the issue:

> handle J:\BuildAgent05\work\e780bd3af5242ffb\ |?{ $_ -imatch 'VBCSCompiler.exe'}
VBCSCompiler.exe   pid: 968    type: File            3C: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools
VBCSCompiler.exe   pid: 968    type: File           5D4: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\VBCSCompiler.exe
VBCSCompiler.exe   pid: 968    type: File           5E0: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\Microsoft.CodeAnalysis.dll
VBCSCompiler.exe   pid: 968    type: File           5E8: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.ValueTuple.dll
VBCSCompiler.exe   pid: 968    type: File           5F4: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Collections.Immutable.dll
VBCSCompiler.exe   pid: 968    type: File           600: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\Microsoft.CodeAnalysis.CSharp.dll
VBCSCompiler.exe   pid: 968    type: File           60C: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.IO.FileSystem.Primitives.dll
VBCSCompiler.exe   pid: 968    type: File           614: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.IO.FileSystem.Primitives.dll
VBCSCompiler.exe   pid: 968    type: File           618: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\Microsoft.CodeAnalysis.VisualBasic.dll
VBCSCompiler.exe   pid: 968    type: File           624: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Reflection.Metadata.dll
VBCSCompiler.exe   pid: 968    type: File           630: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.IO.FileSystem.dll
VBCSCompiler.exe   pid: 968    type: File           63C: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Text.Encoding.CodePages.dll
VBCSCompiler.exe   pid: 968    type: File           644: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Text.Encoding.CodePages.dll
VBCSCompiler.exe   pid: 968    type: File           6F4: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Security.Cryptography.Primitives.dll
VBCSCompiler.exe   pid: 968    type: File           6F8: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Security.Cryptography.Primitives.dll
VBCSCompiler.exe   pid: 968    type: File           6FC: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Threading.Tasks.Extensions.dll
VBCSCompiler.exe   pid: 968    type: File           704: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Threading.Tasks.Extensions.dll
VBCSCompiler.exe   pid: 968    type: File           708: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.IO.Compression.dll
VBCSCompiler.exe   pid: 968    type: File           710: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.IO.Compression.dll
VBCSCompiler.exe   pid: 968    type: File           714: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Xml.ReaderWriter.dll
VBCSCompiler.exe   pid: 968    type: File           71C: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Xml.ReaderWriter.dll
VBCSCompiler.exe   pid: 968    type: File           720: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Xml.XPath.XDocument.dll
VBCSCompiler.exe   pid: 968    type: File           728: J:\BuildAgent05\work\e780bd3af5242ffb\packages\Microsoft.Net.Compilers.2.10.0\tools\System.Xml.XPath.XDocument.dll

At the start of the next build, we try to clean the workspace, and get the following error:

Failed to perform checkout on agent: '"C:\Program Files\Git\bin\git.exe" clean -f -d -x' command failed. exit code: 1
...
stderr: warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/Microsoft.DiaSymReader.Native.amd64.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.IO.Compression.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.IO.FileSystem.Primitives.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.Security.Cryptography.Primitives.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.Text.Encoding.CodePages.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.Threading.Tasks.Extensions.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.Xml.ReaderWriter.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/System.Xml.XPath.XDocument.dll: Invalid argument
warning: failed to remove packages/Microsoft.Net.Compilers.2.10.0/tools/VBCSCompiler.exe: Invalid argument

As a workaround, we have written something into our build scripts to kill VBCSCompiler.exe instances that have open file handles on the current workspace, but this seems like an issue that would affect a number of people, so I wanted to open a ticket.

The build machine does not have visual studio installed. We just install the dev tools.

nickdurcholz avatar Feb 21 '19 13:02 nickdurcholz

Did something change to make this more likely? I wasn't seeing this problem at all until recently and now I'm getting it all over the place.

@vatsalyaagrawal - what did you write to kill the VBCSCompiler.exe instances?

BuairtRi avatar May 22 '19 15:05 BuairtRi

This issue seems to have been resolved by updating to Microsoft.Net.Compilers.3.0.0.

The code we added to the end of our CI build scripts was the following powershell:

$Pids = handle -nobanner $WorkspaceRoot `
    | Where-Object { $_ -imatch 'VBCSCompiler.exe\s+pid:\s+(?<PID>\d+)\s+type:\s+File' } `
    | ForEach-Object { [int]($Matches.PID)} `                                             
    | Select-Object -Unique                                                               
                                                                                          
if ($Pids) {                                                                              
    "Killing the following VBCSCompiler.exe processes: $Pids"                             
    $Pids | ForEach-Object { Stop-Process -Force -Id $_ -ErrorAction SilentlyContinue }   
}                                                                                         

nickdurcholz avatar May 22 '19 15:05 nickdurcholz