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

Suddenly unable to attach and debug dotnet core application in docker container #2994

Closed
adamkarb opened this issue Jun 10, 2021 · 13 comments
Closed
Assignees
Milestone

Comments

@adamkarb
Copy link

I have an existing launch configuration that I have been using to successfully debug a dotnet core application within a Docker container. The configuration I use in launch.json is as follows:

{
    "name": "Docker .NET Core Attach",
    "type": "docker",
    "request": "attach",
    "platform": "netCore",
    "processId": "${command:pickRemoteProcess}",
    "sourceFileMap": {
        "/app": "${workspaceFolder}/repositories/myproject"
    }
}

What is happening as of late suddenly, is that when launching the debug process, the following occurs:

  1. The dropdown asks me which containers I wish to attach. I select my dotnet core API container.
  2. If vsdbg does not exist within the container, choose to install. Works fine.
  3. Immediately afterwards, I get a vscode popup error No process with the specified id is currently running.

Before I began experiencing this bug/error, the "${command:pickRemoteProcess}" would provide me a dropdown of all processes running within the container I chose in step 1, but now it is not doing this, but immediately erroring.

What works:
If I start my dotnet core application in the container, enter the container and find the process ID within, and input it into the processId field of my launch configuration, it will successfully attach.

Are my configurations incorrect suddenly? Is there a better way to configure this setup?

@adamkarb
Copy link
Author

Further context: I found the output from the OUTPUT pane of vscode for the remote-attach command. Not sure yet how to diagnose yet.

Executing: docker exec -i API "sh -s" < "/Users/adam/.vscode/extensions/ms-dotnettools.csharp-1.23.12/scripts/remoteProcessPickerScript"
OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "sh -s": executable file not found in $PATH: unknown
Error Message: Command failed: docker exec -i API "sh -s" < "/Users/adam/.vscode/extensions/ms-dotnettools.csharp-1.23.12/scripts/remoteProcessPickerScript"

@karolz-ms
Copy link
Contributor

@adamkarb could you add repro steps? E.g. does the problem reproduce with vanilla web API app created with dotnet new webapi --no-https?

Also, what is the OS, VS Code, and Docker extension version?

@adamkarb
Copy link
Author

@karolz-ms System and versioning information:

Docker version 20.10.7, build f0df350

VS Code version: Code 1.56.2 (Universal) (054a9295330880ed74ceaedda236253b4f39a335, 2021-05-12T17:44:30.902Z)
OS version: Darwin x64 20.3.0

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz (16 x 2300)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 32.00GB (0.07GB free)
Process Argv --crash-reporter-id 8641fbb2-0011-46a9-817d-eda5a1e01669
Screen Reader no
VM 0%
Extensions (7)
Extension Author (truncated) Version
dotnet-test-explorer for 0.7.5
auto-using Fud 0.7.15
vscode-docker ms- 1.13.0
csharp ms- 1.23.12
mssql ms- 1.10.1
remote-containers ms- 0.177.2
vscodeintellicode Vis 1.2.14

@adamkarb
Copy link
Author

@karolz-ms I just tested with a plain web application in a docker container. I got the exact same results. The remoteProcessPickerScript is somehow not being picked up / executed as indicated by that log output above.

@karolz-ms
Copy link
Contributor

Thanks, Adam. I can reproduce as well.

@karolz-ms
Copy link
Contributor

OK I think I have figured it out. There was a relatively recent change to C# VS Code tools that changed the way process resolution works: dotnet/vscode-csharp#4509

In most cases you won't need to specify the process picker anymore; we default to looking for dotnet process so it should "just work". For reference, this configuration works for me with the plain web API:

{
    "name": "Docker .NET Core Attach",
    "type": "docker",
    "request": "attach",
    "platform": "netCore",
    "sourceFileMap": {
        "/src": "${workspaceFolder}"
    }
}

Please let us know if this gets you unblocked

@adamkarb
Copy link
Author

@karolz-ms I am still suffering from this problem.

The error I get now looks like

Multiple processes were found matching the process name. Attach by process id instead.

There can be multiple dotnet processes running in the same container. Just in my example, for development, my entrypoint is a dotnet run <project> command which will take care of the compilation and execution. Because the pickRemoteProcess choice has been taken away from me, my only recourse without changing my development environment is to

  1. Boot container.
  2. Enter container and list processes to find out which process ID I need.
  3. Go back to launch.json to hardcode it.

This is the return of ps aux in my container

root         1  0.0  0.6 3064072 80316 ?       SLsl 19:35   0:02 dotnet run ./myproject --no-launch-profile --configfile ./
root        48  0.1  0.0      0     0 ?        Z    19:35   0:04 [dotnet] <defunct>
root        65  0.0  0.0      0     0 ?        Z    19:35   0:02 [dotnet] <defunct>
root        85  0.0  0.0      0     0 ?        Z    19:35   0:01 [dotnet] <defunct>
root       160  0.0  0.0   4284   744 pts/0    Ss+  19:35   0:00 /bin/sh
root       175 10.2  0.0      0     0 ?        Z    19:35   6:45 [dotnet] <defunct>
root       395  1.6  5.7 19977160 710644 ?     SLl  19:36   1:04 dotnet exec /app/myproject/bin/container/Debug/netcoreapp2

Why has the ability to pick a remote process been removed completely? Can't a default be supported as well as a user choice?

@karolz-ms
Copy link
Contributor

BTW opening the same issue in multiple repos like this microsoft/vscode#125878 is not going to get you a faster resolution, or win you any friends, frankly

@karolz-ms karolz-ms self-assigned this Jun 11, 2021
@karolz-ms
Copy link
Contributor

karolz-ms commented Jun 11, 2021

Looks like a problem with variable substitution in launch configurations. The following configuration should work:

{
    "name": "Docker .NET Core Attach",
    "type": "docker",
    "request": "attach",
    "platform": "netCore",
    "processId": "${command:pickRemoteProcess}"
},

but it does not (the process picker is never shown). Investigating...

@adamkarb
Copy link
Author

BTW opening the same issue in multiple repos like this microsoft/vscode#125878 is not going to get you a faster resolution, or win you any friends, frankly

I opened that one first, before I realized this was the proper repository for the issue. I went ahead and closed it just for you.

@karolz-ms
Copy link
Contributor

Thanks! I came to believe this is a regression in C# VS Code tooling and I have opened dotnet/vscode-csharp#4607 for the C# tooling owners to take a look

I also noticed the default .NET image does not contain ps executable, so I submitted a PR to switch to Ubuntu-based images as a workaround: #2996 Without ps the process picker will not be able to enumerate processes in the container.

@adamkarb
Copy link
Author

@karolz-ms
Appreciate your diligence on this, will be following closely.

@karolz-ms karolz-ms added the .NET label Jun 11, 2021
@dbreshears dbreshears added this to the 1.15.0 milestone Jun 16, 2021
@dbreshears dbreshears added the P1 label Jun 16, 2021
@karolz-ms
Copy link
Contributor

The next OmniSharp release should have the fix for this debugging scenario--I do not think there is anything on the Docker extension side to change. Resolving as "external" for now, but please reopen/create new issue as necessary if something still does not work.

@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants