Skip to content

Windows + VS Code + WSL + Docker #1941

@agroszer

Description

@agroszer

Environment data

  • debugpy version: 1.8.16
  • OS and version: windows 11 23H2 WSL 2.5.10 ubuntu 22.04
  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.13
  • Using VS Code or Visual Studio: VS Code 1.102.3

Actual behavior

VS Code running on windows, attached to WSL
app/script running in WSL in a docker container
AFAICS port 5678 is exposed to WSL from the container

VS Code fails to connect

Expected behavior

VS Code debugger connects fine

Steps to reproduce:

I shall have a pretty standard launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Remote Attach",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ],
            "logToFile": true
        }
    ]
}

Clicking the start debugging button scrolls the progress a bit then nothing happens
The Debugpy Attacher extension outputs a warning like debug session failed to start

The log shows:

0 Starting Session:
{
    "name": "Python Debugger: Remote Attach",
    "type": "debugpy",
    "request": "attach",
    "connect": {
        "host": "localhost",
        "port": 5678
    },
    "pathMappings": [
        {
            "localRoot": "/home/a/app",
            "remoteRoot": "."
        }
    ],
    "logToFile": true,
    "__configurationTarget": 6,
    "clientOS": "unix",
    "debugOptions": [
        "RedirectOutput",
        "ShowReturnValue"
    ],
    "justMyCode": false,
    "showReturnValue": true,
    "workspaceFolder": "/home/a/app"
}
3 Error:
{}
7 Client --> Adapter:
{
    "command": "disconnect",
    "arguments": {
        "restart": false
    },
    "type": "request",
    "seq": 1
}
7 Client --> Adapter:
{
    "command": "initialize",
    "arguments": {
        "clientID": "vscode",
        "clientName": "Visual Studio Code",
        "adapterID": "debugpy",
        "pathFormat": "path",
        "linesStartAt1": true,
        "columnsStartAt1": true,
        "supportsVariableType": true,
        "supportsVariablePaging": true,
        "supportsRunInTerminalRequest": true,
        "locale": "en",
        "supportsProgressReporting": true,
        "supportsInvalidatedEvent": true,
        "supportsMemoryReferences": true,
        "supportsArgsCanBeInterpretedByShell": true,
        "supportsMemoryEvent": true,
        "supportsStartDebuggingRequest": true,
        "supportsANSIStyling": true
    },
    "type": "request",
    "seq": 2
}
718 Stopping Session

When I try to run attach with debugpy in the very same container with:

./ve/bin/debugpy --connect 5678 --log-to-stderr ./bin/test

I get:

...
D+00000.207: connect(('127.0.0.1', 5678), **{'access_token': None, 'parent_session_pid': None})

I+00000.207: Initial debug configuration: {
                 "qt": "none",
                 "subProcess": true,
                 "python": "/code/ve/bin/python3.11",
                 "pythonEnv": {}
             }

D+00000.207: pydevd.settrace(*(), **{'host': '127.0.0.1', 'port': 5678, 'client_access_token': None, 'ppid': 0, 'suspend': False, 'patch_multiprocessing': True, 'dont_trace_start_patterns': ('/code/ve/lib/python3.11/site-packages/debugpy',), 'dont_trace_end_patterns': ('debugpy_launcher.py',)})

Traceback (most recent call last):
  File "/code/ve/lib/python3.11/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py", line 275, in _on_run
    self.process_net_command_json(self.py_db, json_contents)
  File "/code/ve/lib/python3.11/site-packages/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_process_net_command_json.py", line 197, in process_net_command_json
    assert request.type == "request"
           ^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

What's wrong? How to debug?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions