Skip to content

Debugging fails to start when Visual Studio Code Remote automatically forwards ports from a GitHub Codespace #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jarrodldavis opened this issue Dec 20, 2020 · 5 comments
Assignees
Labels
bug Something isn't working waiting for response

Comments

@jarrodldavis
Copy link

Environment data

  • debugpy version: Not sure, whatever is included in the VS Code Python extension, v2020.12.424452561 (run import debugpy; print(debugpy.__version__) if uncertain) [this didn't work, I get ModuleNotFoundError: No module named 'debugpy']
  • OS and version: macOS 11.1 Big Sur, remoting into a GitHub Codespace running Debian 10 (buster) using this dev container
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.6
  • Using VS Code or Visual Studio: Visual Studio Code

Actual behavior

Debugging fails with connection refused errors (similar to #84) when ports are automatically forward from a Codespace (default behavior of Visual Studio Code).

Expected behavior

Debugging a Django app starts fine even when ports are (automatically) forwarded, or Visual Studio Code doesn't automatically forward ports important for Python debugging.

Steps to reproduce:

  1. Create a GitHub Codespace for a Django app using the Python 3 & Postgres Development Container
  2. Once the Codespace is finished initializing, try to start debugging
  3. Observe that some ports are automatically forwarded by Visual Studio Code
  4. Debugging fails with a Connection refused error
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/vscode/.vscode-remote/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 95, in <module>
    main()
  File "/home/vscode/.vscode-remote/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/__main__.py", line 51, in main
    launcher.connect(host, port)
  File "/home/vscode/.vscode-remote/extensions/ms-python.python-2020.12.424452561/pythonFiles/lib/python/debugpy/launcher/../../debugpy/launcher/__init__.py", line 34, in connect
    sock.connect((host, port))
ConnectionRefusedError: [Errno 111] Connection refused

I was able to work around this issue by disabling automatic port forwarding (setting remote.autoForwardPorts to false) and reloading Visual Studio Code.

@int19h int19h self-assigned this Mar 31, 2021
@int19h int19h added the bug Something isn't working label Mar 31, 2021
@int19h
Copy link
Contributor

int19h commented Aug 10, 2021

This is sort of expected when VSCode remote server forwards all ports, since debugpy uses a bunch of them for local connections.

It appears that there's now a (as yet unstable) VSCode API that extensions can use to tell the port forwarder to ignore some addresses: microsoft/vscode#11561; the Jupyter extension is already using it, so the core Python extension might have to start doing that, as well.

For launch, this should be fairly easy, since only the adapter process opens listener ports, and the extension spawns it directly, so it knows its PID - so PortAttributesProvider can just return ignore for all ports for that PID.

For attach, it's trickier because the adapter gets spawned by the debuggee in that scenario, and the extension doesn't know its PID or port numbers. It looks like the port provider API has an optional command line argument - if it's reliable enough, it could be used to filter anything matching debugpy.adapter. If not, we might need to devise some alternative communication mechanism from the adapter to the extension, that it can use to communicate its PID before it opens any ports.

@karthiknadig, what do you think?

@karthiknadig
Copy link
Member

In the attach case since it is not really spawned by a process under VS Code process tree will the ports be forwarded at all?

@int19h
Copy link
Contributor

int19h commented Aug 17, 2021

@jarrodldavis Does this still reproduce for you? Debugging a web app in a Codespace seems to be working fine for me.

@int19h
Copy link
Contributor

int19h commented Oct 13, 2021

Please re-open if this issue is still relevant.

@int19h int19h closed this as completed Oct 13, 2021
@AndreasLuckert
Copy link

AndreasLuckert commented Aug 8, 2022

Maybe this solution posted on StackOverFlow helps you. It seems to be a similar problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for response
Projects
None yet
Development

No branches or pull requests

4 participants