Support port numbers in attach debug configurations as strings
See original GitHub issueRequested 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:
- Created 2 years ago
- Reactions:11
- Comments:9 (3 by maintainers)
Top GitHub Comments
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.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.