microsoft / vscode-azurefunctions

Azure Functions extension for VS Code
https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions
MIT License
290 stars 134 forks source link

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

Open eli-1716 opened 2 years ago

eli-1716 commented 2 years ago

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:

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

nturinski commented 2 years ago

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.

eli-1716 commented 2 years ago

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.

cptfixit commented 2 years ago

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 commented 2 years ago

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.

3rmir commented 2 years ago

(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

eli-1716 commented 1 year ago

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.

robert1826 commented 1 year ago

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?

ezaspy commented 4 months ago

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