question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core remote debug via SSH isn't working as advertised

See original GitHub issue

https://github.com/microsoft/vscode-remote-release/issues/2074#issuecomment-568572887

from @adaviding

Issue Description

I am following the ssh debug scenario in your documentation.

I cannot remote debug using the SSH technique (hereafter known as “method 1”).

Possibly related to https://github.com/OmniSharp/omnisharp-vscode/issues/3347.

Steps to Reproduce

I am following the ssh debug scenario in your documentation.

I am having a problem with method 1 (remote debugging via ssh).

I have gotten this working with method 2 (remote debugging via docker exec), so you know most of the pieces setup correctly.

Here is the launch.json content which shows how both methods are configured within my instance of VSCode. (Both methods are configured similarly with some minor differences, as shown in your documentation.)

{
    // Method 1 -- Not working
    // This is not currently working.  We are supposed to be able to connect to a remote debugger using this config via ssh
    // This is taken from https://github.com/OmniSharp/omnisharp-vscode/wiki/Attaching-to-remote-processes#configuring-ssh-attach-with-launchjson
    "name": ".NET Core SSH Attach",
    "type": "coreclr",
    "request": "attach",
    "processId": "${command:pickRemoteProcess}",
    "pipeTransport": {
        "pipeProgram": "ssh",
        "pipeArgs": [ "-T", "-i", "C:/Users/ding/.ssh/id_rsa", "-o", "StrictHostKeyChecking=no", "root@localhost", "-p", "10022"],
        //"pipeArgs": [ "-T", "root@localhost", "-p", "10022"],
        "debuggerPath": "/var/vsdbg/vsdbg",
        "pipeCwd": "${workspaceRoot}",
        "quoteArgs": true
    },
    "sourceFileMap": {
        "/home/ExampleAccount/ExampleProject": "${workspaceRoot}"
    }
},
{
    // Method 2 -- Working
    // This is how we remote debug an application running in a docker container.
    // This is taken from https://github.com/OmniSharp/omnisharp-vscode/wiki/Attaching-to-remote-processes#configuring-docker-attach-with-launchjson
    "name": ".NET Core Docker Attach",
    "type": "coreclr",
    "request": "attach",
    "processId": "${command:pickRemoteProcess}",
    "pipeTransport": {
        "pipeProgram": "docker",
        "pipeArgs": [ "exec", "-i", "docker-images_debug_test_1" ],
        "debuggerPath": "/var/vsdbg/vsdbg",
        "pipeCwd": "${workspaceRoot}",
        "quoteArgs": false
    },
    "sourceFileMap": {
        "/home/ExampleAccount/ExampleProject": "${workspaceRoot}"
    }
}

I have also setup and configured openssh-server (running within the docker container) to the point that you can ssh into the container from the host machine by executing a simple command using either Command Prompt or GitBash on the host machine:

ssh -i C:/Users/ding/.ssh/id_rsa -o StrictHostKeyChecking=no root@127.0.0.1 -p 10022

Expected Behavior

Debugger can attach via SSH.

Actual Behavior

When I try to connect a remote debugger using method 1 (via ssh), it doesn’t actually connect; it just hangs.

Logs

remote-attach log

In the OUTPUT tab (with “remote-attach” selected) I can see a message:

Executing: ssh -T -i C:/Users/ding/.ssh/id_rsa -o StrictHostKeyChecking=no root@localhost -p 10022 "sh -s" < C:\Users\ding\.vscode\extensions\ms-vscode.csharp-1.21.9\scripts\remoteProcessPickerScript

At this point I should see some kind of UI which allows me to pick the PID but it doesn’t appear. When I forcibly stop the docker container I immediately see additional text within the OUTPUT tab:

stderr: Connection to localhost closed by remote host.
Error Message: Command failed: ssh -T -i C:/Users/ding/.ssh/id_rsa -o StrictHostKeyChecking=no root@localhost -p 10022 "sh -s" < C:\Users\ding\.vscode\extensions\ms-vscode.csharp-1.21.9\scripts\remoteProcessPickerScript
Connection to localhost closed by remote host.

Environment information

VSCode version: 1.41.1 C# Extension: 1.21.9

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4

Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db

.NET Core SDKs installed: 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.400 [C:\Program Files\dotnet\sdk] 2.1.401 [C:\Program Files\dotnet\sdk] 2.1.403 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.2.107 [C:\Program Files\dotnet\sdk] 2.2.109 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
cpptools ms-vscode 0.26.2
csharp ms-vscode 1.21.9
remote-wsl ms-vscode-remote 0.41.6

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
VoXcommented, Jul 22, 2020

@tungphuong

I ran into this as well on Windows 10 using the Microsoft version of the OpenSSH ssh client. I found two workarounds, either install and specify the full path to a different cygwin based build of the OpenSSH ssh client (I tested with the one that comes with the Windows git installer). Or edit the remoteProcessPickerScript file that the extension attempts to pipe to the ssh connection and add a new line with just the exit command and then one final blank line. Ensure the line endings are set to LF.

C:\Users\user\.vscode\extensions\ms-dotnettools.csharp-1.22.1\scripts\remoteProcessPickerScript

uname && if [ "$(uname)" = "Linux" ] ; then ps -axww -o pid=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= ; elif [ "$(uname)" = "Darwin" ] ; then ps -axww -o pid=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= -c; fi
exit

If you go the script editing route you will probably need to re-edit it every time the extension gets updated. I believe the root cause is how cmd.exe treats the end of file when redirecting to stdin.

0reactions
alanmbarrcommented, Nov 21, 2020

An alternative to Vox’s approach is this

uname && if [ “$(uname)” = “Linux” ] ; then ps -axww -o pid=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= ; exit; elif [ “$(uname)” = “Darwin” ] ; then ps -axww -o pid=,comm=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,args= -c; fi

with a exit; added after the first if block which should avoid having to change the file lineendings. i’m exploring if this is safe to do but seemed to work for my windows machine and the script seems to run the same in linux

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remote debugging .Net Core using ssh on Linux x64 machine ...
This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available,...
Read more >
Debug .NET Core on Linux - Visual Studio (Windows)
Debug .NET Core on Linux using Secure Shell (SSH) by attaching to a process. Prepare your app for debugging. Build and deploy the...
Read more >
Easy Set Up of .NET Core on Raspberry Pi and Remote ...
NET Core development and remote debugging using Visual Studio Code. ... the card to allow remote ssh when transferred to the Raspberry Pi ......
Read more >
Enable Debugging Mode in SSH to Troubleshoot Connectivity ...
This will enable you to see what actually unfolds when you execute an ssh command to connect to a remote Linux server using...
Read more >
Remote Access Overview | Junos OS - Juniper Networks
This topic shows you how to configure remote access using Telnet, SSH, FTP, ... does not reach a Juniper Networks device, for example,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found