'Linux Azure web app service remote debugging

The only known way to debug a Linux Azure web app is to create a TCP tunnel between your machine and Azure which is explained here.

I am able to create the tunnel, SSH and SFTP into the web app using the credentials given from Azure(127.0.0.1 and port) via terminal but having problems with adding the connection to Debug -> Attach to Process in Visual Studio 2022. The response is 'Could not connect to the remote system, connection timed out' and the stack is:

11:24:25.4599569 [Info, Thread 1]   liblinux.RemoteSystemBase: Connecting over SSH to 127.0.0.1:63718
11:24:26.0743705 [Info, Thread 1]   liblinux.IO.RemoteFileSystemImpl: Connecting over SFTP to 127.0.0.1:63718
11:24:56.0883458 [Info, Thread 1]   liblinux.HostKeyVerifier: Connection failed.
11:24:56.0883458 [Info, Thread 1]   liblinux.HostKeyVerifier: Renci.SshNet.Common.SshOperationTimeoutException: Socket read operation has timed out after 30000 milliseconds.
   at Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan readTimeout)
   at Renci.SshNet.Connection.ProtocolVersionExchange.SocketReadLine(Socket socket, TimeSpan timeout, List`1 buffer)
   at Renci.SshNet.Connection.ProtocolVersionExchange.Start(String clientVersion, Socket socket, TimeSpan timeout)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.CreateAndConnectSession()
   at Renci.SshNet.BaseClient.Connect()
   at liblinux.HostKeyVerifier.Connect(BaseClient client)
11:24:56.0883458 [Error, Thread 1]  liblinux.IO.RemoteFileSystemImpl: Connection failure over SFTP to 127.0.0.1:63718
11:24:56.1130928 [Error, Thread 1]  liblinux.IO.RemoteFileSystemImpl: Renci.SshNet.Common.SshOperationTimeoutException: Socket read operation has timed out after 30000 milliseconds.
   at Renci.SshNet.Abstractions.SocketAbstraction.Read(Socket socket, Byte[] buffer, Int32 offset, Int32 size, TimeSpan readTimeout)
   at Renci.SshNet.Connection.ProtocolVersionExchange.SocketReadLine(Socket socket, TimeSpan timeout, List`1 buffer)
   at Renci.SshNet.Connection.ProtocolVersionExchange.Start(String clientVersion, Socket socket, TimeSpan timeout)
   at Renci.SshNet.Session.Connect()
   at Renci.SshNet.BaseClient.CreateAndConnectSession()
   at Renci.SshNet.BaseClient.Connect()
   at liblinux.HostKeyVerifier.Connect(BaseClient client)
   at liblinux.IO.RemoteFileSystemImpl.ConnectCore()
11:24:56.1130928 [Info, Thread 1]   liblinux.RemoteSystemBase: Disconnecting over SSH from "127.0.0.1:63718"

The SSH connection is working fine because on connect I have to accept the connection fingerprint so the problem is with the SFPT connection happening right after that.

Visual Studio 2022 17.1.6, latest

Any good ideas?



Solution 1:[1]

There are two correlated, but rather separate features at play 1) SSH, and 2) Remote Debugging

SSH

As of right now, to my knowledge, SSH into blessed containers-- code publish-- and custom containers-- Docker publish-- is still in "Preview" which means not feature complete, not recommended for production. Please see here (Open SSH from remote shell). Notably, that doc links here (Remote Debugging of Node.js Apps), which suggests Remote Debugging has been enabled for Node.js. However, this blog post is now four years old. Things have probably changed since. So, let's look at the remote debugging feature.

Remote Debugging

To tell if Remote Debugging is available for your current runtime and platform, open Azure portal and navigate to the site in question. Under settings Configuration, look for "Debugging" in the General settings tab. You will either be able to enable Remote Debugging (for instance, for Node.js publish, App Service Windows):

Azure App Service Windows, Node 14

or you will see "Your selected runtime stack does not currently support remote debugging." (for instance, Node.js publish, App Service Linux, .NET 6 publish on App Service Windows):

Azure App Service Windows Dotnet 6

UPDATE: Regarding Visual Studio, VS2022 appears to use PORT 4026 as the default port; however, the port for Azure App Service is still 4024. Recent versions of VS appear to have reverted (17.2.0 and later). For versions prior to VS2022 17.2.0, using Debug\Attach, append port 4024 to the connection URL.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1