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.

Support port numbers in attach debug configurations as strings

See original GitHub issue

Requested feature

Support port numbers in attach debug configurations as strings rather than numbers exclusively.

{
    "name": "Python: Current File",
    "type": "python",
    "request": "attach",
    "connect": {
        "host": "localhost",
        "port": "1234"
    }

Motivation

The attach debug configurations expect a number as port number rather than a string. This prevents variable substitution in launch.json. As an example, the following configuration raises an error on the port key: Incorrect type. Expected "number".

{
    "name": "Python: Current File",
    "type": "python",
    "request": "attach",
    "connect": {
        "host": "localhost",
        "port": "${env:DEFAULT_DEBUGGER_PORT}"
    },
    "console": "integratedTerminal"
}

Use case

Assume that you have to debug your application by attaching to a running process. Assume that you package and debug the application into a container by attaching VSCode to the running container. Finally, assume that you have to debug parallel instances of the application on your local machine. In this scenario each debugger must use a distinct port (this is the case for containers in a podman pod at least because they share the same network). The port could be supplied as an environment variable to each container.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
int19hcommented, Nov 18, 2021

Note that we already did this for processId before, and for the same exact reason.

Given that it’s the second property like that, and that it’s hard to predict all the scenarios in which variable substitution might be useful for one property or another, I feel like this should be generalized to all numeric properties. On debugpy side this would be easy, since there’s a common path for all typed property queries. However, connect.port for attach is a separate thing, because it’s handled entirely by vscode-python.

0reactions
int19hcommented, Sep 27, 2022

I see that I actually commented to that above and forgot about it! 🤦‍♂️

For “listen”, the fix had to be on debugpy side - it was actually more extensive that that and covered all numeric debug configuration properties, not just the port.

But for “connect” (or the legacy top-level “port”), it’s vscode-python that has to parse the port to establish the connection, and it currently just assumes that it’s a valid int: https://github.com/microsoft/vscode-python/blob/3698950c97982f31bb9dbfc19c4cd8308acda284/src/client/debugger/extension/adapter/factory.ts#L48-L52

This is the part that needs fixing. Although I would recommend doing the same thing that debugpy did, and fix this for all non-string configuration properties.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attach debug configuration: support port type as string #137444
The attach debug configurations expect a number as port number rather than a string. This prevents variable substitution in launch.json . As an ......
Read more >
Run/debug configurations | IntelliJ IDEA Documentation
Learn how to use run configurations to run/debug your code in IntelliJ IDEA with various startup properties.
Read more >
Debugging in Visual Studio Code
One of the great things in Visual Studio Code is debugging support. Set breakpoints, step-in, inspect variables and more.
Read more >
Remote Debugger Port Assignments - Visual Studio (Windows)
TCP 4026 (in Visual Studio 2022) is the main port, and is required for all scenarios excluding Azure App Service. You can configure...
Read more >
Documentation » Step Debugging - Xdebug
In more complex set-ups you need to configure the host and port that Xdebug ... For debugging multiple subsequent requests, Xdebug supports ......
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