Repository: stable-diffusion-webui
Issue: [Bug]: Python exception when /sdapi/v1/options called during outstanding POST /sdapi/v1/txt2img
Labels: bug-report

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Everything with this used to be smooth on `8d12a729b8b036cb765cf2d87576d5ae256135c8`, but on the commit listed, I'm hitting issues trying to make concurrent requests to the API. Specifically, it seems to not like it when I call the options endpoint when a POST request to txt2img is already made and waiting.

```
Traceback (most recent call last):
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 407, in run_asgi
      result = await app(  # type: ignore[func-returns-value]
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 407, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
      return await self.app(scope, receive, send)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\fastapi\applications.py", line 271, in __call__
      await super().__call__(scope, receive, send)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\fastapi\applications.py", line 271, in __call__
    await super().__call__(scope, receive, send)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\applications.py", line 125, in __call__
      await self.middleware_stack(scope, receive, send)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\applications.py", line 125, in __call__
    await self.middleware_stack(scope, receive, send)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
      raise exc
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
    raise exc
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
      await self.app(scope, receive, _send)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
    await self.app(scope, receive, _send)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 105, in __call__
      await response(scope, receive, send)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\base.py", line 105, in __call__
    await response(scope, receive, send)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 266, in __call__
      async with anyio.create_task_group() as task_group:
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 266, in __call__
    async with anyio.create_task_group() as task_group:
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
      raise exceptions[0]
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 662, in __aexit__
    raise exceptions[0]
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 269, in wrap
      await func()
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 269, in wrap
    await func()
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 251, in stream_response
      await send(
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\responses.py", line 251, in stream_response
    await send(
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
      await send(message)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\starlette\middleware\errors.py", line 159, in _send
    await send(message)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 494, in send
      output = self.conn.send(event)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 494, in send
    output = self.conn.send(event)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\h11\_connection.py", line 468, in send
      data_list = self.send_with_data_passthrough(event)
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\h11\_connection.py", line 468, in send
    data_list = self.send_with_data_passthrough(event)
    File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\lib\site-packages\h11\_connection.py", line 483, in send_with_data_passthrough
      raise LocalProtocolError("Can't send data when our state is ERROR")
  File "C:\Users\you\.tensorscale\stable-diffusion-webui\venv\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
  h11._util.LocalProtocolError: Can't send data when our state is ERROR
```

### Steps to reproduce the problem

1. Call /sdapi/v1/options 
1. (Maybe) Call /sdapi/v1/progress after options call
1. Start POST to /sdapi/v1/txt2img

Then I would get EOF on the client side

A trace of the problem looks like this, with txt2img resp being unhappy and not writing back at the end 

![image](https://user-images.githubusercontent.com/1476820/218188399-287d5e74-0b8a-4914-b969-db35e24ffa80.png)


### What should have happened?

No exception

### Commit where the problem happens

ea9bd9fc7409109adcd61b897abc2c8881161256

### What platforms do you use to access the UI ?

Windows

### What browsers do you use to access the UI ?

_No response_

### Command Line Arguments

```Shell
--api
```


### List of extensions

n/a

### Console logs

```Shell
They're a bit of a mess, but the traceback is a good summary.
```


### Additional information

_No response_