vscode: Debugger fails to attach to extension (localProcessExtensionHost.ts Could not find a free port for debugging?)

Issue Type: Bug

When trying to debug an extension project, the debugger doesn’t seem to attach:

  • Breakpoints are never hit, even though the extension host is running past them
  • Console output is not sent to the Debug Console (very annoying)
  • When I close the test window, terminating the process, the debugger doesn’t get notified and keeps running
  • When I stop the debugger, the test window doesn’t get notified and stays open

Reproduction uncertain, I’m having about a 95% failure rate trying to debug an extension, with no changes made; it simply works some of the time. (Race condition?)

In the “test window”, the Developer Tools console shows “[Extension Host] Could not find a free port for debugging” from localProcessExtensionHost.ts

I’ve tried specifying some random ports in launch.json, as suggested here, but to no avail (in fact, I get the Warning “Property port is not allowed.”)

Same with the latest insider build.

I’m new to VS Code and dealing with the node debugger, so I don’t know what to look out for yet, I’m sorry if I’m missing something obvious in this first step. I would, for example, like to change the settings with which the extension host tries to find that port: findFreePort(expected, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */); to increase the default 10 tries and 5 seconds, but I can’t find any settings where this would be exposed.

Question asked on Stack Overflow: https://stackoverflow.com/questions/66652751/vs-code-extension-debugger-fails-to-attach

My current launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Extension",
            "type": "extensionHost",
            "request": "launch",
            "runtimeExecutable": "${execPath}",
            "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
            "stopOnEntry": false,
            "sourceMaps": true,
            "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ],
            "trace": true,
            "preLaunchTask": "npm"
        }
    ]
}

I’ve attached the trace log vscode-debugadapter-5c11744c.json.gz

VS Code version: Code 1.54.3 (2b9aebd5354a3629c3aba0a5f5df49f43d6689f8, 2021-03-15T10:55:45.459Z) OS version: Windows_NT x64 10.0.18363

System Info
Item Value
CPUs AMD FX™-6300 Six-Core Processor (6 x 3588)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 15.95GB (7.70GB free)
Process Argv –crash-reporter-id 2f190e4f-e294-4871-bce2-3673cd578662
Screen Reader no
VM 0%
Extensions (10)
Extension Author (truncated) Version
vsc-export asl 1.2.0
vscode-icontheme-nomo-dark be5 1.3.6
problems-fix-runner ctf 0.0.9
jshint dba 0.11.0
vscode-eslint dba 2.1.17
file-icons fil 1.0.29
theme-monokai-pro-vscode mon 1.1.18
vscode-opened-editors Nic 0.0.6
vscode-editor-group-minimizer suh 1.3.2
reopenclosedtab uyi 1.1.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@svArtist If your path makes problems with Powershell, you can try to make VS Code use a different command interpreter just for “automation” (that is when running tasks in terminals). For this there is a setting "terminal.integrated.automationShell.windows"where you could set a different command interpreter (e.g. a classical command prompt). Please note that this setting does not affect the integrated terminals in VS Code.