vscode-azurefunctions icon indicating copy to clipboard operation
vscode-azurefunctions copied to clipboard

Debugging Azure Python functions using VS Code IDE "connect ECONNREFUSED 127.0.0.1:9091"

Open eli-1716 opened this issue 2 years ago • 8 comments

  • VS Code Version: image

  • Azurite Version 3.19.0

  • Core Tools Version: 4.0.4736

  • Function Runtime Version: 4.8.1.18957

Steps to Reproduce:

  1. Start Azurite local storage emulator (for testing durable functions). F1 > Azurite: Start. Azurite service starts successfully.

  2. Hit F5 to debug. Requirements checked/installed, functions are listed, then error box appears. image

  3. Workarounds: Can usually hit Cancel and F5 again, and then debugging starts successfully -OR- can just hit Cancel and run functions successfully without debugging

A colleague and I have both experienced this issue on 2 different machines. Even though we have a workaround we've been attempting for months to eliminate original error, with no success. Issue has persisted through multiple VS Code versions (version noted above is currently installed).

Troubleshooting steps taken:

  • Uninstall / Reinstall VS Code
  • Uninstall / Reinstall Azure Core Tools v3 and v4
  • Downgraded and upgraded Azure Core Tools v3 <-> v4 - Adjusted Function Runtime Version to target Function Version 3 and 4 accordingly.
  • Deleted Azure Functions extension from %USER%.vscode\extension
  • Reinstalled Azure Functions extension
  • Explicitly install Azure Functions extension bindings/bundles
  • My colleague posted to on StackOverflow (Unable to debug Python Azure function in VS Code IDE. Getting connect ECONNREFUSED 127.0.0.1:9091 error - Stack Overflow) We both tried the suggestions.
  • Disable all extensions. This causes a different error. image
  • Disable only Azurite extension and switch from local storage to storage account connection. Same (original error). Workarounds still work.

Note: We are on a corp VPN. However, the issue happens regardless of whether we are connected to the VPN

Possibly Related: Sometimes, after closing VS Code completely and reopening, when I try debugging, I get VS Code error: could not find the task 'func: host start' (image above).

However, if I open a new terminal and run 'func host start', it runs successfully without any issue.

Can usually eliminate it by uninstalling Azure Functions extension and reinstalling via extensions blade. Not exactly sure why this works, but have had to do it numerous times.

This happens every so often, but can't reproduce it reliably or identify a specific pattern.

image

image

image

image

eli-1716 avatar Sep 12 '22 13:09 eli-1716

Hi @eli-1716

Thanks for all of the information. I've tried to reproduce this error with Python 3.9 and 3.8.10 to no avail. Since it's inconsistent, the only thing I can think of is that it's a race condition where Python is telling VS Code it is ready to attach, but it actually isn't.

I think the only thing we could do on our end is to add a task that verifies that the Python task is actually running by looking for its process ID before we try to attach. We'll keep investigating, but we'll try exploring that as a fix unless we can figure out what the root of the problem actually is.

nturinski avatar Oct 04 '22 17:10 nturinski

Sounds good - thank you @nturinski. The possibility of a race condition is something that came up during our debugging attempts and discussions with MS support staff.

eli-1716 avatar Oct 05 '22 18:10 eli-1716

Since it's inconsistent, the only thing I can think of is that it's a race condition where Python is telling VS Code it is ready to attach, but it actually isn't.

My colleagues and I are running into the same problem and I can almost guarantee it's not a race condition. For us, this problem occurs on every Python project, even a brandnew and empty demo project.

After starting the Function and checking with netstat we see a listener op port 7071, but not on 9091. So it looks like the Functions runtime either does not try to, or fails to, open a listener for the debugger.

The Python app runs find and we can interact with it on port 7071. So the Function and its code run. It's just that there's nothing on 9091 for the debugger to connect to. Thus VSCode doesn't show any of the usual information.

Running the latest VSCode with Azure Functions Core Tools 4.x.

cptfixit avatar Nov 02 '22 10:11 cptfixit

After starting the Function and checking with netstat we see a listener op port 7071, but not on 9091. So it looks like the Functions runtime either does not try to, or fails to, open a listener for the debugger.

My colleague has just proven that it's the latter: they decided to do something dirty and run VSCode with local administrative privileges. Starting the Function from VSCode now succeeds in opening both 7071 and 9091 and the debugger can now attach.

This suggests that there's a privileges issue in how the runtime tries to open 9091.

cptfixit avatar Nov 02 '22 11:11 cptfixit

(Re)Installing the azure-core-tools worked for me on MacOS and fixed the issue.

https://learn.microsoft.com/de-de/azure/azure-functions/functions-run-local?tabs=v4%2Cmacos%2Ccsharp%2Cportal%2Cbash

3rmir avatar Nov 12 '22 15:11 3rmir

I've re-installed core tools numerous times, as well as VS Code itself and many of the extensions. None of that fixes the issue for me on Windows 10.

eli-1716 avatar Nov 14 '22 15:11 eli-1716

I encontered the same issue and for me the solution to to make sure the version of the entension bundle in the host.json matches the one that is shown in the terminal when you start the debugging session, I see you have function runtime version is 4.8 while in the host.json you have the range only including v3, did you try updating that to 4.8?

robert1826 avatar Apr 04 '23 20:04 robert1826

Same issue here. I am on Linux Ubuntu 22.04.

I have followed this doc https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python?pivots=python-mode-configuration.

Screenshot from 2024-07-03 09-07-58

When I reach Run the function locally, I hit F5 and get presented with the following error Screenshot from 2024-07-03 09-08-08

ezaspy avatar Jul 03 '24 08:07 ezaspy