stable-diffusion icon indicating copy to clipboard operation
stable-diffusion copied to clipboard

OSError: All ports from 7860 to 7959 are in use. Please close a port

Open fatdennis opened this issue 2 years ago • 11 comments

How to close a port? cannot use SD automatic 1111 after the git pull yesterday (24/10/2022)

fatdennis avatar Oct 25 '22 01:10 fatdennis

I'm having this issue one a clean install today (11/23/22) - Those ports aren't open or blocked as far as I can tell.

Traceback (most recent call last): File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\launch.py", line 251, in start() File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\launch.py", line 246, in start webui.webui() File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\webui.py", line 155, in webui app, local_url, share_url = demo.launch( File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1298, in launch server_name, server_port, local_url, app, server = networking.start_server( File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\venv\lib\site-packages\gradio\networking.py", line 114, in start_server port = get_first_available_port( File "D:\StableDiffusionGUI\Data\stable-diffusion-webui\venv\lib\site-packages\gradio\networking.py", line 65, in get_first_available_port raise OSError( OSError: All ports from 7860 to 7959 are in use. Please close a port. Press any key to continue . . .

Sinphaltimus avatar Nov 23 '22 23:11 Sinphaltimus

I am also experiencing this issue. The issue initially appeared about a week ago, I was able to load the web-UI normally a few days ago but then this issue came back today. I'm not really sure what's going on.

Traceback (most recent call last): File "C:\Users\Slay\sd-webui-new\launch.py", line 295, in start() File "C:\Users\Slay\sd-webui-new\launch.py", line 290, in start webui.webui() File "C:\Users\Slay\sd-webui-new\webui.py", line 140, in webui app, local_url, share_url = shared.demo.launch( File "C:\Users\Slay\sd-webui-new\venv\lib\site-packages\gradio\blocks.py", line 1298, in launch server_name, server_port, local_url, app, server = networking.start_server( File "C:\Users\Slay\sd-webui-new\venv\lib\site-packages\gradio\networking.py", line 114, in start_server port = get_first_available_port( File "C:\Users\Slay\sd-webui-new\venv\lib\site-packages\gradio\networking.py", line 65, in get_first_available_port raise OSError( OSError: All ports from 7860 to 7959 are in use. Please close a port.

SlayTheVirus avatar Dec 09 '22 20:12 SlayTheVirus

P.S.: Restarting worked for me...

Same here, any solution so far? Ports don't seem to be opened.

bybpow avatar Dec 26 '22 11:12 bybpow

I wrote --port 44444 after Launching Web UI with arguments and it finally worked.

Vereinzelte avatar Jan 06 '23 22:01 Vereinzelte

This seems to be a daily thing for me as well. The only solution I have found is doing a full restart of my pc (sometimes more than once). And when my pc restarts, its a grab a cup of coffee kinda wait lol. I know those ports are available because i run a port scan to ensure. I've also changed toe --port flag but that only worked for me once and is only a temporary solution. PC restarts it is! lol

johnnybpena1989 avatar Feb 18 '23 01:02 johnnybpena1989

Here's the solution I found and would like to share.

This works on Windows 10, but should work on other Windows environments as well.

Open Command Prompt and enter the following command:

netstat

This command finds all the processes in use.

Check for the port between 7860 and 7959 with a local address.

For example, if you found that port 7939 is in use, enter the following command:

netstat -ano | findstr :7939

This command finds all the processes currently using port 7939.

Find the value in the "PID" column on the far right of the output after running the command. This is the unique ID of the process using the port.

Enter the following command to terminate the process with the corresponding PID:

taskkill /F /PID [PID] /T

Replace [PID] with the PID value found in the previous step. /F means to force termination. /PID [PID] receives the PID of the process to be terminated. /T means to terminate all processes associated with the target process.

If you have completed these steps, the web-UI should be running again.

Munoy avatar Feb 19 '23 20:02 Munoy

I wrote --port 44444 after Launching Web UI with arguments and it finally worked.

how to?

Agenlone1y2016 avatar Apr 18 '23 14:04 Agenlone1y2016

Here's the solution I found and would like to share.

This works on Windows 10, but should work on other Windows environments as well.

Open Command Prompt and enter the following command:

netstat

This command finds all the processes in use.

Check for the port between 7860 and 7959 with a local address.

For example, if you found that port 7939 is in use, enter the following command:

netstat -ano | findstr :7939

This command finds all the processes currently using port 7939.

Find the value in the "PID" column on the far right of the output after running the command. This is the unique ID of the process using the port.

Enter the following command to terminate the process with the corresponding PID:

taskkill /F /PID [PID] /T

Replace [PID] with the PID value found in the previous step. /F means to force termination. /PID [PID] receives the PID of the process to be terminated. /T means to terminate all processes associated with the target process.

If you have completed these steps, the web-UI should be running again.

johnnybpena1989 avatar Apr 20 '23 03:04 johnnybpena1989

Here's the solution I found and would like to share. This works on Windows 10, but should work on other Windows environments as well. Open Command Prompt and enter the following command:

netstat

This command finds all the processes in use. Check for the port between 7860 and 7959 with a local address. For example, if you found that port 7939 is in use, enter the following command:

netstat -ano | findstr :7939

This command finds all the processes currently using port 7939. Find the value in the "PID" column on the far right of the output after running the command. This is the unique ID of the process using the port. Enter the following command to terminate the process with the corresponding PID:

taskkill /F /PID [PID] /T

Replace [PID] with the PID value found in the previous step. /F means to force termination. /PID [PID] receives the PID of the process to be terminated. /T means to terminate all processes associated with the target process. If you have completed these steps, the web-UI should be running again.

68747470733a2f2f692e696d6775722e636f6d2f33576a426e4e312e676966

same, there's no ports in use shown in netstat.

Holit avatar May 22 '23 02:05 Holit

I know this is a old issue, but it seems no one has found a solution yet. I have found a solution that good work for me, so I want to share it here:

Firstly, this is not a webui or gradio issue, it's a Windows issue.

If you check the NAT tcp port exclusion range using netsh interface ipv4 show excludedportrange protocol=tcp, you will find 7860 falls within some range... (I guess some cracking software takes advantage of Windows' port permission restrictions to achieve cracking, but fails to properly clean up the port permissions after finishing, leading to this issue).

So naturally, it's simple to just remove these restrictions, like this:

net stop winnat
netsh interface ipv4 show excludedportrange protocol=tcp 
net start winnat
netsh interface ipv4 show excludedportrange protocol=tcp

and you can one single line cmd to restart it:

net stop winnat & net start winnat

Now the port should be free to use again.

zhzLuke96 avatar Nov 09 '23 07:11 zhzLuke96

If you check the NAT tcp port exclusion range using netsh interface ipv4 show excludedportrange protocol=tcp, you will find 7860 falls within some range... (I guess some cracking software takes advantage of Windows' port permission restrictions to achieve cracking, but fails to properly clean up the port permissions after finishing, leading to this issue).

So naturally, it's simple to just remove these restrictions, like this:

net stop winnat
netsh interface ipv4 show excludedportrange protocol=tcp 
net start winnat
netsh interface ipv4 show excludedportrange protocol=tcp

Now the port should be free to use again.

This worked flawlessly for me and free'd up the ports. Cheers man! (To people who dont know, open the command prompt or windows power shell and just copy the above text as one command and paste/enter it into the terminal. Done.)

As for your suggested cause. I have never used cracked software. Can you elaborate on that? Possibly you meant something else. I am curious of the cause as this was a new pc build with a legit copy of windows 11 pro.

Thnx!

-edit on reboot i had to apply it again.

TeaRexcellence avatar Dec 19 '23 23:12 TeaRexcellence