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?
Its due to the antivirus. After disabling the antivirus it works fine.
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
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.
If you use a vs code update local.settings.json as
ex settings
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
},
"ConnectionStrings": {
"ConnectionString1": "............."
},
**"Host": {
"LocalHttpPort": 5004
}**
}
then go to http://localhost:5004/api/functionname
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):
- 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)
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
next, issue kill on the two process IDs, like so:
kill -9 14517 14832
that should do it!
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.
navigate to the project folder and run the below command on terminal
func host start --port 7072
Its due to the antivirus. After disabling the antivirus it works fine.
On Windows, Adding ports in the Windows firewall rules solved the issue for me.
Not sure why this resolved it for me, but I had to restart my machine then all was fine.
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.
Try another port. For instance: func host start --verbose --port 11000
On Windows you can just check what app is using this port locally. Go to task manager windows + r
and write resmon
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)
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)
© 2022 - 2024 — McMap. All rights reserved.