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

ThunderboltIoc source generator currupting dictionary and burning CPU cores #5

Open
davkean opened this issue Aug 15, 2023 · 0 comments

Comments

@davkean
Copy link

davkean commented Aug 15, 2023

Folks, I'm from the Visual Studio performance and reliability team, and we've caught an issue via our telemetry where ThunderboltIoc source generators are entering an infinite loop on the following path:

microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.GeneratorDriver.RunGenerators | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.GeneratorDriver.RunGeneratorsCore | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.GeneratorDriver.UpdateOutputs | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.SourceOutputNode`[System.__Canon].AppendOutputs | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.DriverStateTable+Builder.GetLatestStateTableForNode[System.ValueTuple`[System.__Canon,System.__Canon]] | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.SourceOutputNode`[System.__Canon].UpdateStateTable | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.UserFunctionExtensions+<>c__DisplayClass_0`[Microsoft.CodeAnalysis.SourceProductionContext,System.__Canon].<WrapUserAction>b__ | 100%
microsoft.codeanalysis.dll!Microsoft.CodeAnalysis.SourceGeneratorAdaptor.<Initialize>b___ | 100%
thunderboltioc.sourcegenerators.dll!ThunderboltIoc.SourceGenerators.ThunderboltSourceGenerator.Execute | 100%
system.core.dll!System.Collections.Generic.HashSet`[System.__Canon]..ctor | 100%
system.core.dll!System.Collections.Generic.HashSet`[System.__Canon].UnionWith | 100%
system.core.dll!System.Collections.Generic.HashSet`[System.__Canon].AddIfNotPresent | 100%
system.core.dll!System.Collections.Generic.HashSet`[System.__Canon].InternalGetHashCode | 100%
thunderboltioc.sourcegenerators.dll!ThunderboltIoc.SourceGenerators.MethodDefinitionEqualityComparer.GetHashCode | 100%
thunderboltioc.sourcegenerators.dll!ThunderboltIoc.SourceGenerators.RoslynSemanticExtensions.GetMethodFullName | 100%
thunderboltioc.sourcegenerators.dll!ThunderboltIoc.SourceGenerators.RoslynSemanticExtensions.MethodCache | 100%
mscorlib.dll!System.Collections.Generic.Dictionary`[System.__Canon,System.__Canon].Insert

This is occuring due to overlapping read/write from multiple threads in the following method, you can see what's happening described here: https://frugalcafe.beehiiv.com/p/selfinflicted-dos-attack-dictionary-corruption. Please move to a ConcurrentDictionary to avoid this.

https://github.com/AlyElhaddad/ThunderboltIoc/blob/ec72a9de19668036515d5ffbade9bc208bdc8291/src/ThunderboltIoc.SourceGenerators/RoslynSemanticExtensions.cs#L10-L17z

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

No branches or pull requests

1 participant