Vscode-remote-release: Random high ports forwarded when debugging django with launcher

Created on 30 Dec 2020  Â·  4Comments  Â·  Source: microsoft/vscode-remote-release


  • VSCode Version: 1.52.1
  • Local OS Version: macOS 10.15.7
  • Remote OS Version: Debian GNU/Linux 10 (buster)
  • Remote Extension/Connection Type: Docker

Excuse me if the following shouldn't be a bug, but it seems pretty weird to me.

I'm using VSCode remote development to run and debug a django project inside a Docker container with VSCode server in it. In my devcontainer.json I forwarded the port 8000. When I start the debug, I see 4 ports forwarded: port 8000 and other 3 rendom high ports e.g.,:

8000 -> localhost:8000 (the only one I'd expect to see)
34075 -> 127.0.0.1:34075
37301 -> 127.0.0.1:37301
42129 -> 127.0.0.1:42129

Other ports are automatically forwarded if I restart the debug process.
I'm wondering the reason why those extra ports are forwarded and how I can avoid it.

Steps to Reproduce:

  1. in devcontainer.json "forwardPorts": [8000],
  2. Create a launch.json like the following
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "runserver",
                "0.0.0.0:8000"
            ],
            "django": true
        }
    ]
}
  1. Debug a Django project


Does this issue occur when you try this locally?: No
Does this issue occur when you try this locally and all extensions are disabled?: No

containers needs-more-info

Most helpful comment

1.52 detects open ports and forwards them. You can turn this off in the settings either globally in the user settings or in the devcontainer.json using the "settings" property:

    "settings": { 
        "remote.autoForwardPorts": false
    },

All 4 comments

I am observing the same behaviour and am wondering the same.

1.52 detects open ports and forwards them. You can turn this off in the settings either globally in the user settings or in the devcontainer.json using the "settings" property:

    "settings": { 
        "remote.autoForwardPorts": false
    },

Thanx @chrmarti for pointing this out. Just a side question about this topic: why does VSCode open those ports after launching the debugger. I mean, this is my launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "runserver",
                "0.0.0.0:8000"
            ],
            "django": true
        }
    ]
}

Before the debug:

vscode ➜ /workspace (main) $ netstat -ltnp 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.11:37389        0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      1235/python         
tcp6       0      0 :::37463                :::*                    LISTEN      105/node            
tcp6       0      0 :::5432     

During the debug:

vscode ➜ /workspace/web (main) netstat -ltnp 
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:44325         0.0.0.0:*               LISTEN      2156/python         
tcp        0      0 127.0.0.11:37389        0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:44949         0.0.0.0:*               LISTEN      2156/python         
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -                   
tcp        0      0 127.0.0.1:40637         0.0.0.0:*               LISTEN      2156/python         
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      2396/python         
tcp6       0      0 :::37463                :::*                    LISTEN      105/node            
tcp6       0      0 :::5432                 :::*                    LISTEN      - 

(ports 40637, 44325, 44949 are opened and then forwarded if autoForwardPorts is enabled)

Such ports aren't opened if a launch python manage.py runserver 0.0.0.0:8000 from the command line. I think it is a behavior somehow related to VSCode. Am I right?

These ports are probably from the python's debugger. Not sure why there would be 3 ports for that.

Was this page helpful?
0 / 5 - 0 ratings