Adapter bootstrap fails with ConnectionRefusedError on WSL2 VirtioProxy or hostAddressLoopback

Open
#2,071 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

Start in debugpy/adapter/main.py at the adapter's sock.connect((localhost, args.for_server)) call, then reproduce with the provided uv run command under WSL2. Compare behavior with networkingMode=VirtioProxy and hostAddressLoopback=true enabled or disabled; done means debugpy.listen() starts without ConnectionRefusedError under the affected settings.

Written by the indexing model from the issue text.

Description

Before creating a new issue, please check the FAQ to see if your question is answered there.

Environment data

  • debugpy version: 1.8.21
  • OS and version: Windows 11 build 26200.9106, Ubuntu 24.04 on WSL2
  • Python version (& distribution if applicable, e.g. Anaconda): CPython 3.14.4, installed/managed by uv
  • WSL version: 2.7.12.0
  • Using VS Code or Visual Studio: bash only

Actual behavior

debugpy.listen() consistently fails during its internal adapter bootstrap. The adapter immediately fails when connecting back to debugpy's temporary callback listener:

ConnectionRefusedError: [Errno 111] Connection refused

The relevant adapter log lines are:

Sending endpoints info to debug server at localhost:<port>
ConnectionRefusedError: [Errno 111] Connection refused

This occurs before the debuggee starts and without an IDE or debugger client involved.

It occurs deterministically when either networkingMode=VirtioProxy or hostAddressLoopback=true is enabled in %UserProfile%\.wslconfig. Both settings independently trigger the problem.

Adding a time.sleep(0.2) immediately before the following line in debugpy/adapter/__main__.py works around the issue:

sock.connect((localhost, args.for_server))

Expected behavior

debugpy.listen() should start normally under WSL2 with networkingMode=VirtioProxy and/or hostAddressLoopback=true enabled.

Steps to reproduce:

  1. In %UserProfile%\.wslconfig, enable either setting:

    [wsl2]
    networkingMode=VirtioProxy
    

    or:

    [experimental]
    hostAddressLoopback=true
    
  2. Apply the configuration from Windows PowerShell:

    wsl --shutdown
    
  3. Open WSL and run:

    uv run python -Xfrozen_modules=off -m debugpy \
      --listen 127.0.0.1:5678 \
      -c "import time; time.sleep(60)"
    
  4. Observe the immediate ConnectionRefusedError from the debugpy adapter.

  5. Disable the relevant .wslconfig setting, run wsl --shutdown, and repeat. The command succeeds.

Dominant language
Python
Stars
2.5k
Forks
202
Avg merge
5d 1h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/debugpy

All issues in microsoft/debugpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.