Azure-functions-core-tools: func.exe not releasing port on CTRL+C

Created on 15 Oct 2018  路  7Comments  路  Source: Azure/azure-functions-core-tools

Seemingly randomly, after I exit my function app, I am no longer able to open it for a few minutes because func.exe is failing to bind to the port. I'm seeing an error like:

func start
Port 7071 is unavailable. Close the process using that port, or specify another port using --port [-p].

If I change the port, it works, but it's really inconvenient to have to keep changing the port! Please advise how I can debug this or if there's some shadow process I can kill to release the port?

no repro

Most helpful comment

I have the same problem. The port isn't closed completely. The first few seconds after CTRL+C'ing the func.exe, netstat.exe -anb returns this:

  TCP    127.0.0.1:7071         127.0.0.1:50717        FIN_WAIT_2
  TCP    127.0.0.1:7071         127.0.0.1:50719        FIN_WAIT_2
  TCP    127.0.0.1:50717        127.0.0.1:7071         CLOSE_WAIT
  TCP    127.0.0.1:50719        127.0.0.1:7071         CLOSE_WAIT

Then, after Chrome releases the socket, the func.exe side stays in TIME_WAIT for some time (maybe a minute or two):

  TCP    127.0.0.1:7071         127.0.0.1:51397        TIME_WAIT
  TCP    127.0.0.1:7071         127.0.0.1:51399        TIME_WAIT

The above is from running the function with the Visual Studio debugger and creating a single request with Chrome.

It helps to shut down the browser completely before closing the function app. It is not enough to close the Chrome tab (or second window if the first window stays open).
The experience is similar with Edge as the browser.

Environment
Windows 10 1803
Azure Functions Core Tools (2.1.725 Commit hash: 68f448fe6a60e1cade88c2004bf6491af7e5f1df)
Function Runtime Version: 2.0.12134.0
Visual Studio 15.9.0 Preview 3.0

All 7 comments

I can't repro this. I'm assuming you're using Windows, right?
How did you install the cli?

@ahmelsayed @bherila
I have the same issue. For me it happens after an unrelated exception was thrown by the function (#774). Once I resolved that exception this does not happen anymore. Painful. I have hardcoded each function to start at a different port due to this.

PS. I just tried it with a new Function that throws an exception, and I can see that it "locks" the port for like 1 min or more. It only happens when Function errors, and you try to restart the Function.

I'm assuming you're using Windows, right?

Yes, Windows 10. All up to date via WU.

How did you install the cli?

Automatically via VS 2017 and also tried via npm install.

I have the same problem. The port isn't closed completely. The first few seconds after CTRL+C'ing the func.exe, netstat.exe -anb returns this:

  TCP    127.0.0.1:7071         127.0.0.1:50717        FIN_WAIT_2
  TCP    127.0.0.1:7071         127.0.0.1:50719        FIN_WAIT_2
  TCP    127.0.0.1:50717        127.0.0.1:7071         CLOSE_WAIT
  TCP    127.0.0.1:50719        127.0.0.1:7071         CLOSE_WAIT

Then, after Chrome releases the socket, the func.exe side stays in TIME_WAIT for some time (maybe a minute or two):

  TCP    127.0.0.1:7071         127.0.0.1:51397        TIME_WAIT
  TCP    127.0.0.1:7071         127.0.0.1:51399        TIME_WAIT

The above is from running the function with the Visual Studio debugger and creating a single request with Chrome.

It helps to shut down the browser completely before closing the function app. It is not enough to close the Chrome tab (or second window if the first window stays open).
The experience is similar with Edge as the browser.

Environment
Windows 10 1803
Azure Functions Core Tools (2.1.725 Commit hash: 68f448fe6a60e1cade88c2004bf6491af7e5f1df)
Function Runtime Version: 2.0.12134.0
Visual Studio 15.9.0 Preview 3.0

Thanks @ahmelsayed !

I've been seeing the same thing on Ubuntu 18.04 4.15.0-36-generic

Build 2.1.748 handles TIME_WAIT, but I still frequently run into issues with CLOSE_WAIT. It's better, but on Linux I still often need to wait a minute or two for things to reset:

$ netstat -a | grep 7071
tcp        1      0 localhost:33248         localhost:7071          CLOSE_WAIT
tcp        0      0 localhost:7071          localhost:33248         FIN_WAIT2
Was this page helpful?
0 / 5 - 0 ratings