20

I try to run the azure function app (Http Triggerd API) from my local (using VS code). But I'm getting an error "port 7071 is unavailable. Close the process using that port, or specify another port using --port [-p]." I checked the list of ports used using cmd prompt.But 7071 is not in used list. Also tried to run with different port using "func host start --port [p1]", but it throws the same error as above. For all ports it throws the same error. How to resolve this problem?

Karthik Subramaniyam
  • 1,141
  • 2
  • 8
  • 15

11 Answers11

17

Goto Project Properties -> Debug -> Application Argument -> paste this -> host start --pause-on-error --port 5800

you will have new port for your Azure Function: http://localhost:5800/api/Function1

KirtiSagar
  • 574
  • 3
  • 13
  • 1
    This fixed my issue. FYI as of 2/1/2022 using latest template from VS: under Debug : General - click 'Open debug launch profiles UI' Under that it was called 'Command line arguments' – Joe Ruder Feb 01 '22 at 08:10
  • This along with the comment fixed my issue. – MJ Hughes Jan 10 '23 at 14:36
16

Sometimes it might happend that port is in use despite there is no other azure funtion in debug mode.

On Windows10 To solve problem turn on Windows Task Manager ctrl + shift + esc. Find your Azure function proccess and simply kill it. It should help without restarting your PC.

It is how it looks like on my PC: enter image description here

zolty13
  • 1,943
  • 3
  • 17
  • 34
13

If you use a vs code update local.settings.json as

ex settings

enter image description here

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  },
  "ConnectionStrings": {
    "ConnectionString1": "............."

  },
  **"Host": {
    "LocalHttpPort": 5004
  }**
}

then go to http://localhost:5004/api/functionname

Ivan Barayev
  • 2,035
  • 5
  • 24
  • 30
8

This happened to me in linux environment, while trying to run a azure function locally from inside eclipse. turns out that terminating the process from inside the eclipse console DOES NOT kill the process, hence the port being used (7071) is not released till the machine is restarted. Here the detective work needed to figure out if this is the case (linux only):

  1. Run the following command to find out if the port is indeed occupied

sudo lsof -i -P -n | grep LISTEN

In my case, the output looked like this:

func      11421 s-----v  261u  IPv4 105109      0t0  TCP 127.0.0.1:44367 (LISTEN)
func      11421 s-----v  293u  IPv4 103143      0t0  TCP *:7071 (LISTEN)
  1. If you see this, it means the process holding 7071 needs to be killed. For doing so, first find the process id for the process that is holding up the ports, like so:

    ps -ef | grep func | grep -v grep

This will give you the process id to be killed, the output may look something like this:

s-----v  14517     1  6 12:36 ?        00:00:05 func host start
s-----v  14832 14517 11 12:38 ?        00:00:00 /usr/lib/jvm/jdk-17/bin/java -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify -Djava.net.preferIPv4Stack=true -jar /usr/lib/azure-functions-core-tools-4/workers/java/azure-functions-java-worker.jar --host 127.0.0.1 --port 34867 --workerId 1298e58c-8104-4c98-b440-f617b8f6943d --requestId c01f56cd-a29c-4ba6-b147-f2a15ea7c4d6 --grpcMaxMessageLength 2147483647
  1. next, issue kill on the two process IDs, like so:

    kill -9 14517 14832

that should do it!

user2921058
  • 91
  • 1
  • 4
4

If running in development make sure you don't have another azure function sitting in debug mode. I was getting this error until I stopped the other function.

Jagged
  • 41
  • 2
0

Its due to the antivirus. After disabling the antivirus it works fine.

Karthik Subramaniyam
  • 1,141
  • 2
  • 8
  • 15
0

On Windows, Adding ports in the Windows firewall rules solved the issue for me.

Rama
  • 187
  • 1
  • 6
  • 20
0

Not sure why this resolved it for me, but I had to restart my machine then all was fine.

Nathan Hadley
  • 100
  • 1
  • 10
0

To add toi @zolty13 answer

Sometimes it doesn't completely shut down, when you try starting it up again, there's the old process still running, which is why you can't run on that very port, of course, you could easily change the port using the methods provided in the other reply, this isn't efficient as you'd need to update all files using the func project.

@zolty13 provided a solution for windows, however, if you are running on a MacOS, to solve the problem, open spotlight CMD+SPACE -> search and run Activity Monitor -> find your Azure function process and simply kill it. It should help without restarting your PC or changing the port.

It is how it looks on my Mac(Ventura): Activity Monitor Fun Display

Isaac Frank
  • 41
  • 1
  • 5
0

Try another port. For instance: func host start --verbose --port 11000

Benjamin T
  • 11
  • 2
0

navigate to the project folder and run the below command on terminal

func host start --port 7072
Lakmal
  • 779
  • 1
  • 8
  • 16