Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
Oct 15, 2019

Conversation

adamsitnik
Copy link
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.

@@ -351,7 +351,7 @@ public ManagedSymbolModule OpenSymbolFile(string pdbFilePath)
if (firstBytes[0] == 'B' && firstBytes[1] == 'S' && firstBytes[2] == 'J' && firstBytes[3] == 'B')
{
stream.Seek(0, SeekOrigin.Begin); // Start over
ret = new PortableSymbolModule(this, pdbFilePath);
ret = new PortableSymbolModule(this, stream, pdbFilePath);
Copy link
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