dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.94k stars 4.64k forks source link

strange "AccessViolationException" when a "StackOverflowException" is expected inside VS2017 debugger #12167

Closed aviv86 closed 4 years ago

aviv86 commented 5 years ago

Just a simple Net Core 2.1 Console App, and awaiting (probably any) async task before an infinite recursive call.

When running the below piece of code inside Visual Studio 2017, I'd expect a StackOverflowException due the (symbolic) recursion. However, I get a strange AccessViolationException, and the program shuts down abruptly.

If I remove the async call, the stack will overflow as expected, and the IDE points me where the problem is (Same if I replace await httpClient.GetAsync("https://www.ravendb.net") with httpClient.GetAsync("https://www.ravendb.net").Result )

    class Program
    {
        private async Task<string> DoCurlAsync()
        {
            using (var httpClient = new HttpClient())
            using (var httpResponse = await httpClient.GetAsync("https://www.ravendb.net"))
            {
                return await httpResponse.Content.ReadAsStringAsync();
            }
        }

        private void Foo()
        {
            Foo();
        }

        private async Task Test()
        {
            var str = await DoCurlAsync();
            Foo();
        }

        static void Main(string[] args)
        {
            new Program().Test().Wait();
        }

    }
AaronRobinsonMSFT commented 5 years ago

cc @stephentoub

stephentoub commented 5 years ago

@mikem8361, you assigned this to yourself. Does that mean you understand the issue and know it to be in the debugger?

mikem8361 commented 5 years ago

No, I haven't investigated so I don't yet if the a/v is in VS or the runtime. Are you volunteering? :)

stephentoub commented 5 years ago

Are you volunteering? :)

Heh, not currently, I was just tagged and so was looking at the issue.

janvorli commented 5 years ago

I've tried to repro it locally (Windows x64 / x86, Linux x64 / x86) with .NET core 2.1.9 and I always get StackOverflowException, never the AccessViolationException. @aviv86 what runtime / architecture were you getting this with?

AndyAyersMS commented 5 years ago

FWIW I had similar symptoms debugging dotnet/coreclr#23309 where a stack overflow was reported as an AV and I could not get VS to break in at first chance -- the process would just exit. This was with 2.2.2 and VS 15.9.6, x64 debug build of the project.

jkotas commented 5 years ago

with .NET core 2.1.9

@janvorli What is the VS version that you are running in? Note that this bug repros only if you run under VS.

janvorli commented 5 years ago

I am using Visual Studio 2017 15.9.9. And I've tried to run the x64 version under VS (for some weird reason, VS refuses to launch the x86 version using x86 runtime and tries to use the x64 one, so it fails to load it).

tommcdon commented 5 years ago

@cshung

tommcdon commented 5 years ago

Tracking this issue on https://github.com/dotnet/coreclr/issues/18541