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 compiler hang from invalid text in AdditionalFiles #868

Merged
merged 4 commits into from Aug 18, 2021

Conversation

bluetarpmedia
Copy link
Contributor

@bluetarpmedia bluetarpmedia commented Jun 28, 2021

Added a timeout to NegatableTypeOrMemberReferenceRegex and MemberReferenceRegex to prevent a CPU hang when given input that causes (what I believe to be) very expensive regex backtracking.

Incidentally, some invalid input causes a hang but other invalid input just causes a no-match (as expected).

These cause a hang (or timeout when the Regex is given one):

![Microsoft.VisualStudio.Shell.Interop.SVsAppContainerProjectDeploy].   <-- original report

[Microsoft.VisualStud]FooBar
[Microsoft.VisualStudio]FooBar
[aaaaaaaaa.bbbbbbbbbb]FooBar                                            <-- 9 'a' then 10 'b'

But the following do not hang and instead return a Regex with no match (as expected).

[Microsoft.VisualStu]FooBar
[aaaaaaaaa.bbbbbbbbb]FooBar                                             <-- 9 'a' then 9 'b'

Maybe there's something internal to Regex which changes its implementation depending on the length of the input string?

Closes #485

…eRegex and MemberReferenceRegex to prevent CPU hang when given input that can cause expensive regex backtracking.
Copy link
Member

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Thank you for this. Just a couple touch-ups, please.

@AArnott AArnott changed the title Fix for #485 Avoid compiler hang from invalid text in AdditionalFiles Jul 9, 2021
@AArnott
Copy link
Member

AArnott commented Jul 9, 2021

@bluetarpmedia tip: Please use descriptive PR titles.

Not great:
image

Great:
image

You already use the magic Closes #485 string in the PR description (which is great in other ways as well), so thank you for that.

@bluetarpmedia
Copy link
Contributor Author

tip: Please use descriptive PR titles.

Will do, thanks!

Copy link
Member

@AArnott AArnott left a comment

Choose a reason for hiding this comment

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

Thanks!

@AArnott AArnott enabled auto-merge August 17, 2021 17:18
@AArnott AArnott added this to the v17.0 milestone Aug 17, 2021
@bluetarpmedia
Copy link
Contributor Author

Looks like the Linux job failed when restoring packages:

Restoring NuGet packages
  Determining projects to restore...
  Restored /home/vsts/work/1/s/src/Microsoft.VisualStudio.Threading/Microsoft.VisualStudio.Threading.csproj (in 6.69 sec).
  Restored /home/vsts/work/1/s/src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj (in 8.43 sec).
  Restored /home/vsts/work/1/s/src/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic.csproj (in 942 ms).
  Restored /home/vsts/work/1/s/src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj (in 180 ms).
  Restored /home/vsts/work/1/s/src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes.csproj (in 793 ms).
  Restored /home/vsts/work/1/s/test/Microsoft.VisualStudio.Threading.Tests.Win7RegistryWatcher/Microsoft.VisualStudio.Threading.Tests.Win7RegistryWatcher.csproj (in 16 ms).
  Restored /home/vsts/work/1/s/test/Microsoft.VisualStudio.Threading.Tests/Microsoft.VisualStudio.Threading.Tests.csproj (in 4.55 sec).
  Restored /home/vsts/work/1/s/test/IsolatedTestHost/IsolatedTestHost.csproj (in 6 ms).
  Failed to download package 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.16.11.31527.49' from 'https://pkgs.dev.azure.com/azure-public/3ccf6661-f8ce-4e8a-bb2e-eff943ddd3c7/_packaging/2a239fd0-3e21-40b0-b9d6-bc122fec7eb2/nuget/v3/flat2/microsoft.visualstudio.imaging.interop.14.0.designtime/16.11.31527.49/microsoft.visualstudio.imaging.interop.14.0.designtime.16.11.31527.49.nupkg'.
  Response status code does not indicate success: 503 (Service Unavailable).
  Failed to download package 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.16.11.31527.49' from 'https://pkgs.dev.azure.com/azure-public/3ccf6661-f8ce-4e8a-bb2e-eff943ddd3c7/_packaging/2a239fd0-3e21-40b0-b9d6-bc122fec7eb2/nuget/v3/flat2/microsoft.visualstudio.imaging.interop.14.0.designtime/16.11.31527.49/microsoft.visualstudio.imaging.interop.14.0.designtime.16.11.31527.49.nupkg'.
  Response status code does not indicate success: 503 (Service Unavailable).
/opt/hostedtoolcache/dotnet/sdk/5.0.400/NuGet.targets(131,5): error : Failed to download package 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.16.11.31527.49' from 'https://pkgs.dev.azure.com/azure-public/3ccf6661-f8ce-4e8a-bb2e-eff943ddd3c7/_packaging/2a239fd0-3e21-40b0-b9d6-bc122fec7eb2/nuget/v3/flat2/microsoft.visualstudio.imaging.interop.14.0.designtime/16.11.31527.49/microsoft.visualstudio.imaging.interop.14.0.designtime.16.11.31527.49.nupkg'. [/home/vsts/work/1/s/Microsoft.VisualStudio.Threading.sln]
/opt/hostedtoolcache/dotnet/sdk/5.0.400/NuGet.targets(131,5): error : Response status code does not indicate success: 503 (Service Unavailable). [/home/vsts/work/1/s/Microsoft.VisualStudio.Threading.sln]
/opt/hostedtoolcache/dotnet/sdk/5.0.400/NuGet.targets(131,5): error : The feed 'vssdk-public [https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json]' lists package 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.16.11.31527.49' but multiple attempts to download the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in progress. Verify the package exists on the feed and try again. [/home/vsts/work/1/s/Microsoft.VisualStudio.Threading.sln]
/opt/hostedtoolcache/dotnet/sdk/5.0.400/NuGet.targets(131,5): error :   Unable to find package 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime.16.11.31527.49'. [/home/vsts/work/1/s/Microsoft.VisualStudio.Threading.sln]
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                Write-Error: /home/vsts/work/_temp/dd9bf25a-9219-4cad-be91-161af7b85855.ps1:3
Line |
   3 |  .\init.ps1 -AccessToken $AccessToken  -UpgradePrerequisites
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Failure while restoring packages.

@AArnott AArnott merged commit 51ddca0 into microsoft:main Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trailing period in vs-threading.MembersRequiringMainThread.txt causes compiler hang
2 participants