dotnet / roslyn-analyzers

MIT License
1.59k stars 465 forks source link

Stack overflow in ServiceHub.RoslynCodeAnalysisService.exe #7441

Open Infini-PLEX opened 4 weeks ago

Infini-PLEX commented 4 weeks ago

Version Used:

Steps to Reproduce:

  1. Open the solution in VS 2022 Enterprise
  2. Open Program.cs
  3. Wait for a few seconds
  4. If you have just in time debugging, it will pop up
  5. Intellisense shuts down completely and a bunch of crash messages are shown on the toolbar

A minimal repro, with source-code provided, is ideal. Using sharplab is preferred for compiler/language issues whenever possible.

Open Program.cs: ConsoleApp12.zip

It seems that SharpLab is even stricter as code that will compile on my system will not compile there. Sharplab in gist: https://gist.github.com/Infini-PLEX/7facd1abc053f7c62357d89cc1597a94

Diagnostic Id:

Not applicable

Expected Behavior:

Intellisense to work properly.

Actual Behavior:

Stack overflow exception in the program.

Commenting out lines that add strings to messages sometimes gets the code to compile, but it is very unreliable.

Stacktrace: https://gist.github.com/Infini-PLEX/7facd1abc053f7c62357d89cc1597a94 Parallel stacktrace: https://github.com/user-attachments/assets/568961f5-4504-4e87-92d3-f96c89c6dc70

dotnet-issue-labeler[bot] commented 4 weeks ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 4 weeks ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

jcouv commented 2 weeks ago

FWIW, the code in project can be shrunk. Here's the smallest repro I got so far:

using System.Diagnostics;

public class TesseractException : Exception
{
    public override string Message
    {
        get
        {
            string message = "";
            bool b = true;
            message += b ? "" : "";
            message += Process.ProcessorAffinity.ToString();
            for (int i = 0; i < 42; ++i)
            {
                message += Process.Modules[42]?.ToString();
            }

            return message;
        }
    }

    Process Process { get; set; }
}

The stack overflow has thousands of repeating frames on this method: Microsoft.CodeAnalysis.FlowAnalysis.DataFlow.PointsToAnalysis.PointsToAnalysis+PointsToDataFlowOperationVisitor.HandleEscapingOperation(Microsoft.CodeAnalysis.IOperation, Microsoft.CodeAnalysis.IOperation, Analyzer.Utilities.PooledObjects.PooledDictionary2<Microsoft.CodeAnalysis.IOperation,Builder>)`

AlekseyTs commented 1 week ago

PointsToAnalysis is not a part of compiler, it is one of the roslyn-analyzers. Going to move the issue there.

AlekseyTs commented 1 week ago

@dotnet/roslyn-analysis FYI

buyaa-n commented 1 week ago

CC @mavasani

jaredpar commented 1 week ago

@arkalyanms, @JoeRobich, @sharwell this is a VS crash that seems to be mostly coming from analyzers.