Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: RuntimeError("Cannot add middleware after an application has started") #7759

Closed
1 task done
NoteToSelfFindGoodNickname opened this issue Feb 12, 2023 · 22 comments
Closed
1 task done
Labels
bug-report Report of a bug, yet to be confirmed

Comments

@NoteToSelfFindGoodNickname

Is there an existing issue for this?

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

What happened?

venv "C:\Users\tomwe\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: ea9bd9f
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
Loading weights [e406a20c1b] from C:\Users\tomwe\stable-diffusion-webui\models\Stable-diffusion\galaxytimemachinesGTM_v1.safetensors
Creating model from config: C:\Users\tomwe\stable-diffusion-webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 2.6s (create model: 0.3s, apply weights to model: 0.6s, apply half(): 0.5s, move model to device: 0.5s, load textual inversion embeddings: 0.7s).
Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch().
Traceback (most recent call last):
File "C:\Users\tomwe\stable-diffusion-webui\launch.py", line 361, in
start()
File "C:\Users\tomwe\stable-diffusion-webui\launch.py", line 356, in start
webui.webui()
File "C:\Users\tomwe\stable-diffusion-webui\webui.py", line 232, in webui
app.add_middleware(GZipMiddleware, minimum_size=1000)
File "C:\Users\tomwe\stable-diffusion-webui\venv\lib\site-packages\starlette\applications.py", line 135, in add_middleware
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
Drücken Sie eine beliebige Taste . . .

Steps to reproduce the problem

Download latest version
Nothing special

What should have happened?

Start fine.

Commit where the problem happens

ea9bd9f

What platforms do you use to access the UI ?

Windows

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

didnt change anything

List of extensions

never started

Console logs

venv "C:\Users\tomwe\stable-diffusion-webui\venv\Scripts\Python.exe"
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: ea9bd9fc7409109adcd61b897abc2c8881161256
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
Loading weights [e406a20c1b] from C:\Users\tomwe\stable-diffusion-webui\models\Stable-diffusion\galaxytimemachinesGTM_v1.safetensors
Creating model from config: C:\Users\tomwe\stable-diffusion-webui\configs\v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 2.6s (create model: 0.3s, apply weights to model: 0.6s, apply half(): 0.5s, move model to device: 0.5s, load textual inversion embeddings: 0.7s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Traceback (most recent call last):
  File "C:\Users\tomwe\stable-diffusion-webui\launch.py", line 361, in <module>
    start()
  File "C:\Users\tomwe\stable-diffusion-webui\launch.py", line 356, in start
    webui.webui()
  File "C:\Users\tomwe\stable-diffusion-webui\webui.py", line 232, in webui
    app.add_middleware(GZipMiddleware, minimum_size=1000)
  File "C:\Users\tomwe\stable-diffusion-webui\venv\lib\site-packages\starlette\applications.py", line 135, in add_middleware
    raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
Drücken Sie eine beliebige Taste . . .

Additional information

No response

@NoteToSelfFindGoodNickname NoteToSelfFindGoodNickname added the bug-report Report of a bug, yet to be confirmed label Feb 12, 2023
@NoteToSelfFindGoodNickname
Copy link
Author

This helped:

Open the Command Prompt or the Windows PowerShell.

Navigate to your Stable Diffusion folder using the cd command. For example, if your Stable Diffusion folder is located at C:\artificial-intelligence-tools\stable-diffusion-webui, you would run the following command:

cd C:\artificial-intelligence-tools\stable-diffusion-webui
.\venv\Scripts\Activate.bat
pip install fastapi==0.90.1
deactivate

Close cmd or powershell
Start Stable Diffusion as you normally would.

@ClashSAN
Copy link
Collaborator

we have another issue for it here - #7714

@qw576483
Copy link

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

@natureXD
Copy link

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

My problems is solved with your method, thank you very much.

@AlexLin625
Copy link

Same issue but not fixed after degrading my fastapi to either 0.90 or 0.89

I'm using the binary pakage in the release tab.

PS D:\Users\11591\stable-diffusion-webui> .\run.bat
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug  1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Commit hash: 48a15821de768fea76e66f26df83df3fddf18f4b
Fetching updates for Stable Diffusion...
Checking out commit for Stable Diffusion with hash: "c12d960d1ee4f9134c2516862ef991ec52d3f59e"...
Installing requirements for Web UI
Launching Web UI with arguments:
No module 'xformers'. Proceeding without it.
LatentDiffusion: Running in v-prediction mode
DiffusionWrapper has 865.91 M params.
Loading weights [bfcaf07557] from D:\Users\11591\stable-diffusion-webui\webui\models\Stable-diffusion\768-v-ema.ckpt
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 5.1s (0.2s create model, 3.1s load weights).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Traceback (most recent call last):
  File "D:\Users\11591\stable-diffusion-webui\webui\launch.py", line 325, in <module>
    start()
  File "D:\Users\11591\stable-diffusion-webui\webui\launch.py", line 320, in start
    webui.webui()
  File "D:\Users\11591\stable-diffusion-webui\webui\webui.py", line 224, in webui
    app.add_middleware(GZipMiddleware, minimum_size=1000)
  File "D:\Users\11591\stable-diffusion-webui\system\python\lib\site-packages\starlette\applications.py", line 135, in add_middleware
    raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
请按任意键继续. . .
PS D:\Users\11591\stable-diffusion-webui>

@sdlkhfksl
Copy link

Installing requirements for Web UI
Launching Web UI with arguments: --medvram --opt-split-attention
No module 'xformers'. Proceeding without it.
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading weights [fc2511737a] from D:\sd.webui\webui\models\Stable-diffusion\chilloutmix_NiPrunedFp32Fix.safetensors
Applying cross attention optimization (Doggettx).
Textual inversion embeddings loaded(0):
Model loaded in 110.4s (1.3s create model, 108.3s load weights).
Running on local URL: http://127.0.0.1:7860

To create a public link, set share=True in launch().
Traceback (most recent call last):
File "D:\sd.webui\webui\launch.py", line 325, in
start()
File "D:\sd.webui\webui\launch.py", line 320, in start
webui.webui()
File "D:\sd.webui\webui\webui.py", line 224, in webui
app.add_middleware(GZipMiddleware, minimum_size=1000)
File "D:\sd.webui\webui\venv\lib\site-packages\starlette\applications.py", line 135, in add_middleware
raise RuntimeError("Cannot add middleware after an application has started")
RuntimeError: Cannot add middleware after an application has started
请按任意键继续. . .

how to resolve this problem?

@AlexLin625
Copy link

I forgot to config Python path in webui_user.
After setting the Python path to the included python in venv, and downgrading fastapi, it works fine.

@billautomata
Copy link

billautomata commented Mar 6, 2023

does anyone know why every single python project is plagued by this problem where you run the program and stop it, and then it won't start again, and nothing changed except for a bunch of invisible upstream shit you didn't ask for

Is there any way I can immunize myself against this? I'm always having to burn a few hours figuring out why there is some insane conflict with a project that was otherwise running correctly.

@chen9916
Copy link

chen9916 commented Mar 7, 2023

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

this works thanks somuch

@MartyMcFlyInTheSky
Copy link

Just a stupid note but don't forget you gotta launch webui-user.bat and not webui.bat directly or the environment variables will not be set correctly!

@chickenrofls
Copy link

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

Thank you so much for this! This resolved my problem.

@janwilmans
Copy link

same problem on 5ab7f21 pip install --upgrade fastapi==0.90.1 fixed it for me too

@vijayrajesh
Copy link

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

Thank you

@Lebski
Copy link

Lebski commented Jun 11, 2023

On mac os

# pull newest changes in repository
git pull 

# update requirements 
./venv/bin/python -m pip install -r requirements.txt

@Graylington
Copy link

Graylington commented Jul 4, 2023

.\venv\Scripts\python.exe -m pip install --upgrade fastapi==0.90.1

This work in version 1.3.2, but needs to be repeated again and again as it immediately reverts the downgrade and updates to fastapi-0.94.0 when the relaunching.

I found replacing the version number in "requirements_versions.txt" fixes this. Any idea if this will break anything?

@TomKranenburg
Copy link

Still staggering on with this problem. I have to revert it every time it's updated.

@janwilmans
Copy link

I don't see it on tag: v1.4.0, origin/master, hash 394ffa7, which is using fastapi==0.94.0. do a 'git log' and check you are actually on the last version?

@TomKranenburg
Copy link

I don't see it on tag: v1.4.0, origin/master, hash 394ffa7, which is using fastapi==0.94.0. do a 'git log' and check you are actually on the last version?

Am indeed.

@janwilmans
Copy link

I'm not sure what the problem could be, could you try removing your 'venv' directory and run with:

set PYTHON=C:\Users\Jan\AppData\Local\Programs\Python\Python310\python.exe
set GIT=
set VENV_DIR=
set COMMANDLINE_ARGS=--no-half-vae --xformers --api --autolaunch
call webui.bat

Where set PYTHON points to your python installation?

@JohannesVod
Copy link

Try add " fastapi==0.90.1" in requirements_versions.txt file located in your SD folder.

@bemonthh
Copy link

SD klasörünüzde bulunan gereksinimleri_versions.txt dosyasına " fastapi==0.90.1" eklemeyi deneyin.

C:\Stable-Diffusion\A1111\webui\requirements_versions.txt
I have added these
torchmetrics==0.11.4
fastapi==0.90.1

and added requirements.txt

torchmetrics==0.11.4

and

C:\Stable-Diffusion\A1111\webui\models\Stable-diffusion
I downloaded 1 model and placed it in this location

I solved a lot of problems and finally I was able to open it

@kimseokho
Copy link

  1. error
  2. update.bat
  3. fastapi==0.90.1 (add)
  4. error
  5. fastapi==0.94.0 (modify) (02/26/2024 기준)
  6. sussess

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report Report of a bug, yet to be confirmed
Projects
None yet
Development

No branches or pull requests