Repository: AUTOMATIC1111/stable-diffusion-webui

Issue #10625: [Bug]: h11._util.LocalProtocolError: Can't send data when our state is ERROR
Created: 2023-05-22T08:58:11Z
Is there an existing issue for this?

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

What happened?
It very strong that when use webui , it could not see the problem, but when use API, it usually release this issue
Exception in callback H11Protocol.timeout_keep_alive_handler()
handle: <TimerHandle when=30411.431255625 H11Protocol.timeout_keep_alive_handler()>
File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/h11/_connection.py", line 483, in send_with_data_passthrough
raise LocalProtocolError("Can't send data when our state is ERROR")
Steps to reproduce the problem
Just common call the API
What should have happened?
It is very stange, sometimes it will happen, but in some times , the same prompt, it could work good
Commit where the problem happens
Common call api
What platforms do you use to access the UI ?
Linux
What browsers do you use to access the UI ?
Microsoft Edge
Command Line Arguments
(no background:1.30)，(There is only 1 Africa black boy:1.4), (front_view, full_body:1.50), cartoon ,with a yellow Lakers basketball shirt and blue shorts standing with his hands in his pockets and his hair in the air
, best quality, 8K,( extreme detail description:1.4), (sharp focus:1.4), <lora:zby-50k-000010:0.5>
List of extensions
No extension
Console logs
Traceback (most recent call last):
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 109, in __call__
    await response(scope, receive, send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 270, in __call__
    async with anyio.create_task_group() as task_group:
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 273, in wrap
    await func()
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 134, in stream_response
    return await super().stream_response(send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 255, in stream_response
    await send(
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in _send
    await send(message)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 513, in send
    output = self.conn.send(event)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/h11/_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/h11/_connection.py", line 483, in send_with_data_passthrough
    raise LocalProtocolError("Can't send data when our state is ERROR")
h11._util.LocalProtocolError: Can't send data when our state is ERROR
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 429, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/fastapi/applications.py", line 273, in __call__
    await super().__call__(scope, receive, send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
    raise exc
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 109, in __call__
    await response(scope, receive, send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 270, in __call__
    async with anyio.create_task_group() as task_group:
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 273, in wrap
    await func()
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/base.py", line 134, in stream_response
    return await super().stream_response(send)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/responses.py", line 255, in stream_response
    await send(
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in _send
    await send(message)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 513, in send
    output = self.conn.send(event)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/h11/_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "/aml/stable-diffusion-webui/venv/lib/python3.10/site-packages/h11/_connection.py", line 483, in send_with_data_passthrough
    raise LocalProtocolError("Can't send data when our state is ERROR")
h11._util.LocalProtocolError: Can't send data when our state is ERROR
Additional information
I just check a lot of issue, but not see same as mine, any expert  please help me to fix the issue, Thanks

Duplicate issue #11990: [Bug]: when loading webui with SDXL checkpoint and sdxl vae, ERROR:asyncio:Exception in callback H11Protocol.timeout_keep_alive_handler()
Created: 2023-07-25T14:22:56Z
Is there an existing issue for this?

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

What happened?
when i try the SDXL after update version 1.5.0,it happened
but if i starting webui with other 1.5 models it comes good
Steps to reproduce the problem

Go to ....
Press ....
...

What should have happened?
it should no problem when i try a text2img with SDXL
Version or Commit where the problem happens
Version: v1.5.0
What Python version are you running on ?
Python 3.10.x
What platforms do you use to access the UI ?
Windows
What device are you running WebUI on?
Nvidia GPUs (RTX 20 above)
Cross attention optimization
Automatic
What browsers do you use to access the UI ?
Microsoft Edge
Command Line Arguments
ERROR:asyncio:Exception in callback H11Protocol.timeout_keep_alive_handler()
handle: <TimerHandle when=14340.765 H11Protocol.timeout_keep_alive_handler()>
Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 249, in _fire_event_triggered_transitions
    new_state = EVENT_TRIGGERED_TRANSITIONS[role][state][event_type]
KeyError: <class 'h11._events.ConnectionClosed'>
提示：Python 运行时抛出了一个异常。请检查疑难解答页面。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 383, in timeout_keep_alive_handler
    self.conn.send(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 493, in send_with_data_passthrough
    self._process_event(self.our_role, event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 242, in _process_event
    self._cstate.process_event(role, type(event), server_switch_event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 238, in process_event
    self._fire_event_triggered_transitions(role, event_type)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 251, in _fire_event_triggered_transitions
    raise LocalProtocolError(
h11._util.LocalProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
*** API error: POST: http://127.0.0.1:7860/run/predict {'error': 'LocalProtocolError', 'detail': '', 'body': '', 'errors': "Can't send data when our state is ERROR"}
    Traceback (most recent call last):
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
        await self.app(scope, receive, _send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 109, in __call__
        await response(scope, receive, send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 270, in __call__
        async with anyio.create_task_group() as task_group:
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
        raise exceptions[0]
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 273, in wrap
        await func()
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 134, in stream_response
        return await super().stream_response(send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 255, in stream_response
        await send(
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
        await send(message)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 512, in send
        output = self.conn.send(event)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
        data_list = self.send_with_data_passthrough(event)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 483, in send_with_data_passthrough
        raise LocalProtocolError("Can't send data when our state is ERROR")
    h11._util.LocalProtocolError: Can't send data when our state is ERROR

---
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 428, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\fastapi\applications.py", line 273, in __call__
    await super().__call__(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 109, in __call__
    await response(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 270, in __call__
    async with anyio.create_task_group() as task_group:
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 273, in wrap
    await func()
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 134, in stream_response
    return await super().stream_response(send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 255, in stream_response
    await send(
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
    await send(message)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 512, in send
    output = self.conn.send(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 483, in send_with_data_passthrough
    raise LocalProtocolError("Can't send data when our state is ERROR")
h11._util.LocalProtocolError: Can't send data when our state is ERROR
List of extensions
no
Console logs
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Version: v1.5.0
Commit hash: a3ddf464a2ed24c999f67ddfef7969f8291567be

Checking roop requirements
Install insightface==0.7.3
Installing sd-webui-roop requirement: insightface==0.7.3
Install onnx==1.14.0
Installing sd-webui-roop requirement: onnx==1.14.0
Install onnxruntime==1.15.0
Installing sd-webui-roop requirement: onnxruntime==1.15.0
Install opencv-python==4.7.0.72
Installing sd-webui-roop requirement: opencv-python==4.7.0.72

Launching Web UI with arguments: --theme dark --xformers --disable-nan-check --api --autolaunch --no-gradio-queue
Civitai Helper: Get Custom Model Folder
Civitai Helper: Load setting from: E:\sd-webui-aki-v4.2\extensions\Stable-Diffusion-Webui-Civitai-Helper\setting.json
Civitai Helper: No setting file, use default
Tag Autocomplete: Could not locate model-keyword extension, LORA/LYCO trigger word completion will be unavailable.
[-] ADetailer initialized. version: 23.7.9, num models: 9
[AddNet] Updating model hashes...
[AddNet] Updating model hashes...
2023-07-25 21:49:17,237 - ControlNet - INFO - ControlNet v1.1.233
ControlNet preprocessor location: E:\sd-webui-aki-v4.2\extensions\sd-webui-controlnet\annotator\downloads
2023-07-25 21:49:17,336 - ControlNet - INFO - ControlNet v1.1.233
sd-webui-prompt-all-in-one background API service started successfully.
2023-07-25 21:49:19,856 - roop - INFO - roop v0.0.2
2023-07-25 21:49:19,857 - roop - INFO - roop v0.0.2
Loading weights [1f69731261] from E:\sd-webui-aki-v4.2\models\Stable-diffusion\底模\sd_xl_base_0.9.safetensors
*Deforum ControlNet support: enabled*
Creating model from config: E:\sd-webui-aki-v4.2\repositories\generative-models\configs\inference\sd_xl_base.yaml
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
[Lobe]: Initializing Lobe
[AgentScheduler] Task queue is empty
[AgentScheduler] Registering APIs
Startup time: 29.2s (launcher: 11.7s, import torch: 3.3s, import gradio: 1.4s, setup paths: 0.7s, other imports: 1.0s, list SD models: 0.2s, load scripts: 7.8s, scripts before_ui_callback: 0.2s, create ui: 1.5s, gradio launch: 0.4s, app_started_callback: 0.7s).
Loading VAE weights specified in settings: E:\sd-webui-aki-v4.2\models\VAE\sdxl_vae.safetensors
Applying attention optimization: xformers... done.
Model loaded in 18.1s (load weights from disk: 1.5s, create model: 1.0s, apply weights to model: 9.1s, apply half(): 3.4s, load VAE: 0.3s, move model to device: 1.8s, load textual inversion embeddings: 0.2s, calculate empty prompt: 0.7s).
ERROR:asyncio:Exception in callback H11Protocol.timeout_keep_alive_handler()
handle: <TimerHandle when=14340.765 H11Protocol.timeout_keep_alive_handler()>
Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 249, in _fire_event_triggered_transitions
    new_state = EVENT_TRIGGERED_TRANSITIONS[role][state][event_type]
KeyError: <class 'h11._events.ConnectionClosed'>
提示：Python 运行时抛出了一个异常。请检查疑难解答页面。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 383, in timeout_keep_alive_handler
    self.conn.send(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 493, in send_with_data_passthrough
    self._process_event(self.our_role, event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 242, in _process_event
    self._cstate.process_event(role, type(event), server_switch_event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 238, in process_event
    self._fire_event_triggered_transitions(role, event_type)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_state.py", line 251, in _fire_event_triggered_transitions
    raise LocalProtocolError(
h11._util.LocalProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSE
*** API error: POST: http://127.0.0.1:7860/run/predict {'error': 'LocalProtocolError', 'detail': '', 'body': '', 'errors': "Can't send data when our state is ERROR"}
    Traceback (most recent call last):
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
        await self.app(scope, receive, _send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 109, in __call__
        await response(scope, receive, send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 270, in __call__
        async with anyio.create_task_group() as task_group:
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
        raise exceptions[0]
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 273, in wrap
        await func()
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 134, in stream_response
        return await super().stream_response(send)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 255, in stream_response
        await send(
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
        await send(message)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 512, in send
        output = self.conn.send(event)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
        data_list = self.send_with_data_passthrough(event)
      File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 483, in send_with_data_passthrough
        raise LocalProtocolError("Can't send data when our state is ERROR")
    h11._util.LocalProtocolError: Can't send data when our state is ERROR

---
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 428, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\fastapi\applications.py", line 273, in __call__
    await super().__call__(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 109, in __call__
    await response(scope, receive, send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 270, in __call__
    async with anyio.create_task_group() as task_group:
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 273, in wrap
    await func()
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\base.py", line 134, in stream_response
    return await super().stream_response(send)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\responses.py", line 255, in stream_response
    await send(
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
    await send(message)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 512, in send
    output = self.conn.send(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
  File "E:\sd-webui-aki-v4.2\python\lib\site-packages\h11\_connection.py", line 483, in send_with_data_passthrough
    raise LocalProtocolError("Can't send data when our state is ERROR")
h11._util.LocalProtocolError: Can't send data when our state is ERROR
Additional information
No response

Closing comment (2023-09-08T06:05:15Z): Duplicate of #10625 -- not necessarily SDXL related. Has something to do with when something takes longer than usual to load. I know this since this error is very consistent if you have a bunch of extra networks, and attempt to generate an image before all the extra networks have finished loading.

hi,,,what do you men of"networks"? any idea of fixing this issue