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

Avoid spinning attempting to create a folder #68394

Merged
merged 1 commit into from
Jun 5, 2023
Merged

Conversation

sharwell
Copy link
Member

@sharwell sharwell commented May 31, 2023

Fixes AB#1812892

@sharwell sharwell requested a review from a team as a code owner May 31, 2023 15:31
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 31, 2023
{
// If we still can't create the folder after 5 seconds, assume we will not be able to create it.
// Return null to indicate this provider cannot provide source for the document.
return null;
Copy link
Member

@Cosifne Cosifne May 31, 2023

Choose a reason for hiding this comment

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

Fine with this approach.
But I look at the caller here https://sourceroslyn.io/#Microsoft.CodeAnalysis.Features/MetadataAsSource/MetadataAsSourceFileService.cs,108
Looks like it assumes the return value of this method can't be null. (line 177)
So maybe we need to handle the failed case more properly, instead of throwing the unreachable exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I misread the null check in the caller.

Copy link
Member Author

Choose a reason for hiding this comment

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

➡️ Rewrote this to continue as it did before, but to just skip writing the file to disk if the location is not accessible. Roslyn will treat the result as an empty document.

@sharwell sharwell marked this pull request as draft May 31, 2023 19:36
@sharwell sharwell marked this pull request as ready for review June 5, 2023 13:25
// Mark read-only
new FileInfo(fileInfo.TemporaryFilePath).IsReadOnly = true;
// Mark read-only
new FileInfo(fileInfo.TemporaryFilePath).IsReadOnly = true;
Copy link
Member

Choose a reason for hiding this comment

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

Why are we creating a new FileInfo w/o using it?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are using the IsReadOnly setter.

➡️ This code did not change.

Copy link
Member

Choose a reason for hiding this comment

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

This code did not change

Yea, I see that, just wondering if we should use this new FileInfo instead afterward.

@@ -172,13 +195,16 @@ public DecompilationMetadataAsSourceFileProvider(IImplementationAssemblyLookupSe
}
}

using (var textWriter = new StreamWriter(fileInfo.TemporaryFilePath, append: false, encoding: MetadataAsSourceGeneratedFileInfo.Encoding))
if (!skipWritingFile)
Copy link
Member

Choose a reason for hiding this comment

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

What's the consequence of not creating the file? We'd simply try again the next time it was request?

Copy link
Member Author

Choose a reason for hiding this comment

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

That seems to be the case. Also, the compilation that gets created for it will see an empty file at that location with an error about failing to load the file contents.

Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to show the golden bar here? Or just maybe log the DirectoryNotFoundException or UnauthorizedAccessException so we have some traces of what's going on here

Copy link
Member

Choose a reason for hiding this comment

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

Looks like my question is asked in the preview comment : )

Copy link
Member Author

Choose a reason for hiding this comment

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

We should still get that. I'm not sure how to force this situation locally so it's hard to test.

@sharwell sharwell merged commit 59ceeed into dotnet:main Jun 5, 2023
@sharwell sharwell deleted the no-spin branch June 5, 2023 21:00
@ghost ghost added this to the Next milestone Jun 5, 2023
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants