Skip to content

ConnectionRefusedError: [WinError 10061] when press F5 to start debugging #10741

Closed

Description

@BobAnkh

Environment data

  • VS Code version: 1.43.1
  • Extension version (available under the Extensions sidebar): 2020.3.69010
  • OS and version: Windows 10 1909
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.0 64-bit in Anaconda
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda 4.8.2

Expected behaviour

The debugger should start and enter a debug session

Actual behaviour

Fail to start the debugger when I press F5.

It first print the following sentence in the terminal:

 $ G:/Anaconda/Scripts/activate

Then pop up the warning:

Code_RsomXEQtTS

Then print the following sentences:

$  env DEBUGPY_LAUNCHER_PORT=4625 G:\\Anaconda\\envs\\pytor\\python.exe c:\\Users\\lenovo
\\.vscode\\extensions\\ms-python.python-2020.3.69010\\pythonFiles\\lib\\python\\debugpy\\
wheels\\debugpy\\launcher g:\\VSCodeProject\\Self-Learning\\helloworld.py
Traceback (most recent call last):
  File "G:\Anaconda\envs\pytor\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "G:\Anaconda\envs\pytor\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "c:\Users\lenovo\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher\__main__.py", line 80, in <module>
    main()
  File "c:\Users\lenovo\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher\__main__.py", line 42, in main
    launcher.connect(launcher_port)
  File "c:\Users\lenovo\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher/../..\debugpy\launcher\__init__.py", line 27, in connect
    sock.connect(("127.0.0.1", launcher_port))
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

Code_NxMjMLWVgY

The chinese means Unable to connect because the target computer actively refuse

Steps to reproduce:

  1. create a helloword.py with only one sentence print('helloworld')
  2. press F5

Logs

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

User belongs to experiment group 'AlwaysDisplayTestExplorer - experiment'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - control'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'WebHostNotebook - control'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> py -3.7 -c "import sys;print(sys.executable)"
> py -3.6 -c "import sys;print(sys.executable)"
> py -3 -c "import sys;print(sys.executable)"
> py -2 -c "import sys;print(sys.executable)"
> G:\Anaconda\envs\pytor\python.exe -c "import sys;print(sys.executable)"
> G:\Anaconda\envs\pytor\python.exe -c "import jupyter"
> G:\Anaconda\envs\pytor\python.exe -c "import jupyter"
> G:\Anaconda\envs\pytor\python.exe -c "import notebook"
> G:\Anaconda\envs\pytor\python.exe -c "import notebook"
Starting Jedi Python language engine.
> conda info --json
> conda env list
> conda info --json
> G:\Anaconda\envs\pytor\python.exe -m flake8 "--ignore=F403, F405" --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s g:\VSCodeProject\Self-Learning\helloworld.py
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -m flake8 "--ignore=F403, F405" --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s g:\VSCodeProject\Self-Learning\helloworld.py
cwd: g:\VSCodeProject\Self-Learning
##########Linting Output - flake8##########
> conda env list
> G:\Anaconda\envs\pytor\python.exe -c "import sys;print(sys.prefix)"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -c "import sys;print(sys.prefix)"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -c "import sys;print(sys.executable)"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -c "import sys;print(sys.executable)"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -m site --user-site
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe -m site --user-site
cwd: g:\VSCodeProject\Self-Learning
> G:\Anaconda\envs\pytor\python.exe completion.py
cwd: c:\Users\lenovo\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
> G:\Anaconda\envs\pytor\python.exe completion.py
cwd: c:\Users\lenovo\.vscode\extensions\ms-python.python-2020.3.69010\pythonFiles
> conda info --json

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

Here I only paste what is printed after I press F5

[Extension Host] request undefined 
{command: "initialize", arguments: {…}, type: "request", seq: 1}
console.ts:137 [Extension Host] request undefined 
{command: "launch", arguments: {…}, type: "request", seq: 2}
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Shell path 'Python Debug Console'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Shell path identified as shell 'other'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Terminal name 'Python Debug Console' identified as shell 'other'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: [object Object]. Shell identified as other (Terminal name is Python Debug Console)
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Shell path 'G:\Git\bin\bash.exe'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Shell path identified as shell 'bash'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Terminal shell path 'G:\Git\bin\bash.exe' identified as shell 'bash'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: [object Object]. Shell identified as bash (Terminal name is Python Debug Console)
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Shell identified as 'bash'
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Cached data exists getEnvironmentVariables, g:\VSCodeProject\Self-Learning\helloworld.py
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Get Conda environments, Class name = b, completed in 0ms, has a truthy return value, Arg 1: false, Return Value: [{"name":"base","path":"G:\\Anaconda"},{"name":"pytor","path":"G:\\Anaconda\\envs\\pytor"}]
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaVersion-Args=
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Cached data exists KeyPrefix=Cache_Method_Output_b.getCondaFileFromInterpreter-Args="G:\\Anaconda\\envs\\pytor\\python.exe"-Arg-Separator-"pytor"
console.ts:137 [Extension Host] Info Python Extension: 2020-03-24 19:44:08: Get Conda File from interpreter, Class name = b, completed in 0ms, has a truthy return value, Arg 1: "G:\\Anaconda\\envs\\pytor\\python.exe", Arg 2: "pytor", Return Value: "G:\\Anaconda\\Scripts\\conda.exe"
console.ts:137 [Extension Host] response undefined 
{type: "response", seq: 3, command: "runInTerminal", request_seq: 4, success: true, …}
console.ts:137 [Extension Host] request undefined 
{command: "disconnect", arguments: {…}, type: "request", seq: 4}
log.ts:197   ERR timeout after 500 ms: Error: timeout after 500 ms
    at t.RawDebugSession.handleErrorResponse (file:///G:/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:952)
    at file:///G:/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2954:250
    at async t.RawDebugSession.shutdown (file:///G:/Microsoft VS Code/resources/app/out/vs/workbench/workbench.desktop.main.js:2952:336)

Other info I think may be helpful

My launch.json:

{
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

My settings.json

{
    "python.pythonPath": "G:\\Anaconda\\envs\\pytor\\python.exe",
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.enabled": true,
    "python.formatting.provider": "yapf",
    "python.autoComplete.extraPaths": ["./pytorch"],
}

And, when I add "python.terminal.activateEnvironment": false to the settings.json, the warning no longer appear. But I still prefer to activate environment when starting debugger. Also it seems to ocasionally suceed after several minutes but I don't think it's a good way to face the problem.

Activity

  1. added
    triage-needed
    bug
    on Mar 24, 2020
  2. ghost removed
    triage-needed
    on Mar 24, 2020
  3. int19h commented on Mar 25, 2020

    @int19h

    You mention that with "python.terminal.activateEnvironment": false, you're not seeing the error message - does this mean that debugger is working fine for you in that case? Or is it failing in a different way?

    Also, can you please try adding "logToFile": true to your launch.json, and share all files matching debugpy*.log that you should get in the folder where the extension was installed (something like C:\Users\...\.vscode\extensions\ms-python.python-2020.3.69010)?

  4. BobAnkh commented on Mar 26, 2020

    @BobAnkh
    Author

    Pavel Minaev (@int19h)
    When I add "python.terminal.activateEnvironment": false to my settings.json, the debugger is working fine, which prints helloworld in my helloworld case, though it does not activate my conda.

    Here is my debugpy*.log file when the debugger fails to start:

    debugpy.launcher-2744.log

    debugpy.adapter-9580.log

    Hope these may help you.

    PS: Is it possible that these problems are caused because I'm using git bash as my terminal? (But I didn't face these problems in previous versions)

    Thanks.

  5. int19h commented on Mar 26, 2020

    @int19h

    I can't think of any reason why Bash would make a difference... but other repros that we're seeing are all on Linux, so perhaps it is related. Could you switch to cmd.exe temporarily, and try it with and without activation, to see if that matters?

  6. BobAnkh commented on Mar 26, 2020

    @BobAnkh
    Author

    Pavel Minaev (@int19h)
    I have tried cmd and powershell, and they both work fine in my case, with or without activation. Later I will try to configure WSL to see if it works fine.

  7. BobAnkh commented on Mar 26, 2020

    @BobAnkh
    Author

    Pavel Minaev (@int19h)
    I have tried WSL, and it works fine in ssh remote mode. It fails to start debugger when I just use wsl bash as the terminal (but I think it is due to other reasons not relevant to this issue)

  8. int19h commented on Mar 26, 2020

    @int19h

    Thank you very much - this is incredibly helpful!

  9. omartin2010 commented on Mar 27, 2020

    @omartin2010

    I actually have that same issue when connecting to a remote device (using SSH remote), both from my Mac and from my Windows machine.

    env DEBUGPY_LAUNCHER_PORT=44257 /usr/bin/python3.6 /home/omartin/.vscode-server-insiders/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher /home/omartin/proj/inferencing/testing_code/mp.py 
    Traceback (most recent call last):
      File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "/home/omartin/.vscode-server-insiders/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher/__main__.py", line 80, in <module>
        main()
      File "/home/omartin/.vscode-server-insiders/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher/__main__.py", line 42, in main
        launcher.connect(launcher_port)
      File "/home/omartin/.vscode-server-insiders/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher/../../debugpy/launcher/__init__.py", line 27, in connect
        sock.connect(("127.0.0.1", launcher_port))
    ConnectionRefusedError: [Errno 111] Connection refused
    

    This didn't happen a few days ago. I also don't have a conda environment in this case, I'm using the OS python installation. This happens to be an NVIDIA Jetson device, so unable to easily install conda there.

  10. zeal-up commented on Mar 31, 2020

    @zeal-up

    I have the same issue using the remote development function in Vscode(using ssh connecting mode). Here is my environment:

    • VSCode Version: 1.43.1
    • Local OS Version: windows 10
    • Remote OS Version: Ubuntu 14
    • Remote Extension/Connection Type: SSH

    Steps to Reproduce:

    1. connect to host
    2. debug an arbitrary file(python)

    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

    I can successfully connect to a remote host in Vscode using SSH connecting. And actually I have used the remote debug function for several days. I can still successfully connect to the remote host in the VScode. However, when I try to debug a python file, vscode throw an error as:

      File "/home/lab-lin.ziyao/.vscode-server/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher/__main__.py", line 42, in main
        launcher.connect(launcher_port)
      File "/home/lab-lin.ziyao/.vscode-server/extensions/ms-python.python-2020.3.69010/pythonFiles/lib/python/debugpy/no_wheels/debugpy/launcher/../../debugpy/launcher/__init__.py", line 27, in connect
        sock.connect(("127.0.0.1", launcher_port))
    

    and popup an error window like:
    image

    The issue is not removed even I add python.terminal.activateEnvironment": false to the setting.json

  11. zeal-up commented on Mar 31, 2020

    @zeal-up

    Update:
    I finally solve this issue after downgrade the python extension version!
    The version causes the issue:2020.3.69010
    I downgrade to:2020.2.64397

  12. int19h commented on Apr 1, 2020

    @int19h

    microsoft/debugpy#84 is the primary issue tracking this bug now, so I'll close this one as a dupe.

  13. ghost removed on Apr 1, 2020
  14. locked as resolved and limited conversation to collaborators on Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions