Skip to content

make sure that SymbolReader.Dispose closes all opened pdb files#979

Merged
brianrob merged 4 commits intomicrosoft:masterfrom
adamsitnik:fileInUse
Oct 15, 2019
Merged

make sure that SymbolReader.Dispose closes all opened pdb files#979
brianrob merged 4 commits intomicrosoft:masterfrom
adamsitnik:fileInUse

Conversation

@adamsitnik
Copy link
Copy Markdown
Member

I've recently profiled an app using PerfView, opened the trace file, used Goto Source (Def), closed the Source Window, modified the app source code and tried to rebuild the app.

The rebuild has failed with file in use exception:

C:\Program Files\dotnet\sdk\3.0.100-preview9-013617\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(153,5): warning MSB3026: Could not copy "obj\Release\netcoreapp3.0\win-x64\ReportedTime.pdb" to "bin\Release\netcoreapp3.0\win-x64\publish\ReportedTime.pdb". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Projects\PerfViewDemo\ReportedTime\bin\Release\netcoreapp3.0\win-x64\publish\ReportedTime.pdb' because it is being used by another process.  [C:\Projects\PerfViewDemo\ReportedTime\0_ReportedTime.csproj]

This PR helps with that by making sure that when the SymbolReader.Dispose is called, it closes all the opened pdb files.

It's still not a perfect solution because SymbolReader.Dispose is called on the static symbol reader instance only when a new trace file is opened:

using (var reader = etlDataFile.GetSymbolReader(Viewer.StatusBar.LogWriter,

s_symbolReader.Dispose();

So closing the Source Code window still keeps the .pdf file opened but opening another trace file closes it. A better solution would require much more changes related to symbol reader cache lifetime management but I don't think that it's worth it as of today.

{
stream.Seek(0, SeekOrigin.Begin); // Start over
ret = new PortableSymbolModule(this, pdbFilePath);
ret = new PortableSymbolModule(this, stream, pdbFilePath);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a minor bug fix: this method opens a stream, seeks to the begining of it but when it creates and instance of PortableSymbolModule it does not reuse the stream but instead calls a ctor that opens the file one more time:

public PortableSymbolModule(SymbolReader reader, string pdbFileName) : this(reader, File.Open(pdbFileName, FileMode.Open, FileAccess.Read, FileShare.Read), pdbFileName) { }

so far we always had the file opened twice

@brianrob brianrob merged commit b09cd21 into microsoft:master Oct 15, 2019
@adamsitnik adamsitnik deleted the fileInUse branch October 16, 2019 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants