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

[Bug]: OSError: Port 7860 is in use. If a gradio.Blocks is running on the port, you can close() it or gradio.close_all().

Open DarkAlchy opened this issue 2 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

When you reset the UI (apply changes, etc...) it causes this error in Linux (being far more secure than WIndows)

Steps to reproduce the problem

.

What should have happened?

It should just work as in Windows by applying what it said that I posted in the title.

Commit where the problem happens

3fe9e9e54dcfc41d7c5ee6976f83b0de29fd3dda

What platforms do you use to access UI ?

Windows, Linux

What browsers do you use to access the UI ?

Google Chrome, Microsoft Edge

Command Line Arguments

No response

Additional information, context and logs

No response

DarkAlchy avatar Jan 11 '23 02:01 DarkAlchy

An alternative can be

gradio_blocks = gr.Blocks(port=8000)

you're specifying the gradio app to ran on port 8000

Another option is to use the following command

def my_function(x):
    return x + 1

gr.Interface(fn=my_function, inputs="text", outputs="text", port=8888).launch()

What the code does it increments the port number by .So the first port number when running the app will be 7861. I hope this helps Good luck

paulmunyao avatar Mar 17 '23 14:03 paulmunyao

I'm having the same issue, I'm using the --api --port {number} argument to change the port and this was no problem but now it is causing an issue and is claiming my port is in use when it most definitely isn't in use. This is on windows 10

TWIISTED-STUDIOS avatar Mar 17 '23 18:03 TWIISTED-STUDIOS

Another option is to kill the PID using the following command

lsof -i :7868

Then using the folliwing to kill the PID

sudo <PID USER>

paulmunyao avatar Mar 17 '23 21:03 paulmunyao

@TWIISTED-STUDIOS Kindly terminating the PID by killing the PID as explained earlier then let me know how it goes I would be more than glad to help

paulmunyao avatar Mar 17 '23 21:03 paulmunyao

@TWIISTED-STUDIOS Kindly terminating the PID by killing the PID as explained earlier then let me know how it goes I would be more than glad to help

sorry only just seen this i feel that restarting the computer fixed the issue however its back again and im not sure what keeps causing it

TWIISTED-STUDIOS avatar Apr 10 '23 17:04 TWIISTED-STUDIOS

@TWIISTED-STUDIOS Did you kill the PID If you didn't kill the PID try following the recommendation I gave you earlier in the comment section above

paulmunyao avatar Apr 12 '23 10:04 paulmunyao

@TWIISTED-STUDIOS Did you kill the PID If you didn't kill the PID try following the recommendation I gave you earlier in the comment section above

Interestingly enough, I had a look through a list of all the processes and their respective ports that were in use to then be prepared to kill the PID of the process but to my surprise not a single process was using the listed port. So that was confusing. - you can rectify it by shutting down and rebooting, it's just an inconvenience.

TWIISTED-STUDIOS avatar Apr 12 '23 10:04 TWIISTED-STUDIOS

@TWIISTED-STUDIOS Ok

paulmunyao avatar Apr 12 '23 11:04 paulmunyao

I also have the same error, modify the port also did not help, I once had the same problem, reboot to solve, but this reboot also did not work.


Traceback (most recent call last): File "D:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\networking.py", line 121, in start_server s.bind((LOCALHOST_NAME, server_port)) PermissionError: [WinError 10013] Made an attempt to access the socket in a way that access rights are not allowed.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\AI\stable-diffusion-webui\launch.py", line 38, in main() File "D:\AI\stable-diffusion-webui\launch.py", line 34, in main start() File "D:\AI\stable-diffusion-webui\modules\launch_utils.py", line 334, in start webui.webui() File "D:\AI\stable-diffusion-webui\webui.py", line 395, in webui app, local_url, share_url = shared.demo.launch( File "D:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1745, in launch server_name, server_port, local_url, app, server = networking.start_server( File "D:\AI\stable-diffusion-webui\venv\lib\site-packages\gradio\networking.py", line 124, in start_server raise OSError( OSError: Port 7868 is in use. If a gradio.Blocks is running on the port, you can close() it or gradio.close_all().

zpengcom avatar Jun 08 '23 09:06 zpengcom

I found this problem with:OSError: All ports from 7860 to 7959 are in use. Please close a port Same

Changing the port to a non - 7860 to 7959 port will fix it

zpengcom avatar Jun 08 '23 10:06 zpengcom

Still facing this issue when using port 9900, and lsof -i:9900 shows nothing.

Dixeran avatar Jun 09 '23 09:06 Dixeran

Hello @Dixeran You've solved the problem?

paulmunyao avatar Jun 14 '23 06:06 paulmunyao

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

Now the port should be free to use again.

UPDATE: one line to do it

net stop winnat && net start winnat

zhzLuke96 avatar Nov 09 '23 07:11 zhzLuke96