microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
175 stars 26 forks source link

Visual Studio 2022 and Docker project debugging issues #396

Open rh101 opened 1 year ago

rh101 commented 1 year ago

Something broke as a result of either a Visual Studio update, a Docker Desktop update, or something I've added to my project, but I can't seem to be find a way to diagnose the issue.

Visual Studio 2022 v17.7.0 and Docker Desktop 4.22.0 using latest WSL2 on Windows 10 Pro (32GB RAM, Ryzen 5XXX series CPU).

I have a VS solution with over 40 projects (WebAPI services etc), and the docker compose file has 27 services defined, and these include MongoDb, PostgreSQL and RabbitMQ.

Starting up the project, everything builds fine, but then it gets to this point:

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------

...and then everything stops...

After waiting several minutes, and hitting the 'Stop Debugging' button, many popups appear (perhaps one per WebAPI service): image

On occasion VS2022 would completely freeze if I attempt to stop it while it is in this state.

Sometimes it actually continues past this point:

-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/System.Private.CoreLib.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
[02:52:41 WRN] Overriding address(es) 'https://+:443, http://+:80'. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/System.Runtime.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Step into: Stepping over non-user code 'Program.<Main>'
Step into: Stepping over non-user code 'Program.<Main>$'
Step into: Stepping over non-user code 'Program.<<Main>$>d__0..ctor'
Loaded '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/7.0.10/Microsoft.Extensions.Options.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Loaded '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/7.0.10/Microsoft.Extensions.Logging.Abstractions.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

... and once again, everything stops... no more console output, services can't be connected to etc.

Other times, it works, like nothing was wrong at all, and everything starts up correctly.

This issue is happening with the eShopOnContainers sample too, so it's not limited to my project.

Note that if I use docker compose up outside of Visual Studio, then all docker containers start up correctly and everything works as expected.

I can't quite figure out what is causing all of this. If someone has a solution, then great, and if not, then I would appreciate any guidance as to where I should start looking in order to track down the root cause of this problem.

rh101 commented 1 year ago

What seems to temporarily fix the issue when it stops working is to do this:

Exit Docker Desktop. Wait ~10 seconds. Shut down WSL (wsl --shutdown). Wait a few seconds. Restart Docker Desktop Delete all containers belonging to the project. Run the project (rebuilds all containers).

After that, everything works fine for at least 5 or so start/stop debugging sessions. Once it fails, repeat above.

Yomphex commented 1 year ago

Can you access vsdebugger.azureedge.net? In my case it's giving 404 error, something probably went wrong in my country's domain side.

patverb commented 1 year ago

While launching may take a while (1-2 minutes) sometimes I'm unable to reproduce the issue with the eShopOnContainers example.

Does it happen with high frequency with the eShopOnContainers project? If you have a high repo project you can share that might help diagnose the issue. Even better would be if you posted the issue on DeveloperCommunity and provide a dump file to help me see if I can figure out what's going on.

rh101 commented 1 year ago

Does it happen with high frequency with the eShopOnContainers project?

Starting and stopping the project approximately 8 times reproduces the issue on my PC.

If you have a high repo project you can share that might help diagnose the issue.

Unfortunately that won't be possible, so I'll need to ensure that I can reproduce the issue with an open source project.

Even better would be if you posted the issue on DeveloperCommunity and provide a dump file to help me see if I can figure out what's going on.

That can be done. Can you please explain how I can generate the dump file that you are referring to? I also have the logs generated by the Docker Desktop diagnostic tool, which was run when the issue occurred, if they would help in any way.

patverb commented 1 year ago

To create a dump file: open task manager -> details tab -> right click on devenv.exe -> create memory dump file. Do that when VS hanging and that will show what VS is trying to do. You can also throw in the logs too, more information won't hurt.

rh101 commented 1 year ago

To create a dump file: open task manager -> details tab -> right click on devenv.exe -> create memory dump file. Do that when VS hanging and that will show what VS is trying to do. You can also throw in the logs too, more information won't hurt.

Thank you for the info. The issue has been logged with relevant files attached (devenv dump file was zipped to 1GB): https://developercommunity.visualstudio.com/t/Visual-Studio-2022-and-Docker-project-de/10449745

antonbanton commented 3 months ago

I experience the same/simillar problem.

I have two different WebAPI solutions and they both work with the debugger if I run them as Windows Container (Hyper-V) in docker-desktop. However when I run them as Linux Containers i WSL2, the endpoints work as expected but then get the same behaivor as above whenever i try to debug them with Visual Studio 2022 by attaching to process.

I created a new "Weaterforecast" solution in purpose of trying to figure out what was wrong while starting off on a clean slate. Whenever I would debug this new WebAPI there was no problem with the debugger.

However if I added any of the characters åäö either in the name of the controller, a method or in any variable.

The behavior you describes above would come back as soon as i tried to debug that specific endpoint with åäö.