Karthik Subramaniyam
Karthik Subramaniyam

Reputation: 1201

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

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?

Upvotes: 26

Views: 28113

Answers (13)

Piotr
Piotr

Reputation: 1177

On Windows you can just check what app is using this port locally. Go to task manager windows + r and write resmon

run window

Then go to the network tab and TCP connections section. Then sort by local Port and search for the port you are interested in (7071 in your case)

resmon network -> tcp connections section

In my case, the issue was, that for some weird reasons, Spotify took 7071 port. So you have to check who is using it and if possible close the app (or change the port to something else as other answers suggested)

Upvotes: 0

Tang Thanh Tam
Tang Thanh Tam

Reputation: 501

I just restarted my computer, and it works ^^

Upvotes: 0

Lakmal
Lakmal

Reputation: 918

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

func host start --port 7072

Upvotes: 1

Benjamin T
Benjamin T

Reputation: 11

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

Upvotes: 0

Isaac Frank
Isaac Frank

Reputation: 129

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

Upvotes: 0

user2921058
user2921058

Reputation: 111

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!

Upvotes: 10

Eng. Saleh Albalkhi
Eng. Saleh Albalkhi

Reputation: 209

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

Upvotes: 20

zolty13
zolty13

Reputation: 2231

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

Upvotes: 23

Nathan Hadley
Nathan Hadley

Reputation: 100

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

Upvotes: 0

KirtiSagar
KirtiSagar

Reputation: 584

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

Upvotes: 18

Jagged
Jagged

Reputation: 41

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.

Upvotes: 4

Rama
Rama

Reputation: 307

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

Upvotes: 0

Karthik Subramaniyam
Karthik Subramaniyam

Reputation: 1201

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

Upvotes: 0

Related Questions