Python RuntimeError:无法对TCPTTransport执行操作处理程序已关闭

Python RuntimeError:无法对TCPTTransport执行操作处理程序已关闭,python,gunicorn,fastapi,starlette,uvicorn,Python,Gunicorn,Fastapi,Starlette,Uvicorn,我正在尝试使用autocannon工具在本地机器上进行HTTP基准测试,这是我在FastAPI+uvicorn基础上构建的全新项目设置 但在某个时刻或随机(我不知道发生了什么)我遇到了ASGI异常 [2019-11-14 14:16:40 +0100] [98098] [ERROR] Exception in ASGI application Traceback (most recent call last): File "/Users/yigidix/Projects/url_shorte

我正在尝试使用
autocannon
工具在本地机器上进行HTTP基准测试,这是我在
FastAPI
+
uvicorn
基础上构建的全新项目设置

但在某个时刻或随机(我不知道发生了什么)我遇到了ASGI异常

[2019-11-14 14:16:40 +0100] [98098] [ERROR] Exception in ASGI application
Traceback (most recent call last):
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/fastapi/applications.py", line 139, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/applications.py", line 134, in __call__
    await self.error_middleware(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 178, in __call__
    raise exc from None
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 156, in __call__
    await self.app(scope, receive, _send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 73, in __call__
    raise exc from None
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 62, in __call__
    await self.app(scope, receive, sender)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 590, in __call__
    await route(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 208, in __call__
    await self.app(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/routing.py", line 44, in app
    await response(scope, receive, send)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/responses.py", line 125, in __call__
    "headers": self.raw_headers,
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/exceptions.py", line 59, in sender
    await send(message)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/starlette/middleware/errors.py", line 153, in _send
    await send(message)
  File "/Users/yigidix/Projects/url_shortener/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 482, in send
    self.transport.write(b"".join(content))
  File "uvloop/handles/stream.pyx", line 673, in uvloop.loop.UVStream.write
  File "uvloop/handles/handle.pyx", line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x7fb255569780>; the handler is closed
我试图增加工人人数。我仍然得到这些例外

要进行基准测试,我需要:

autocannon -c 100 -d 40 -p 10 localhost:8000/shorten -H "Content-Type: application/json" -m POST -b '{"url": "http://yigitgenc.com"}'

另外:我的数据库(
PostgreSQL
)在
Docker
容器上工作。我还做异步数据库交互(当然)。添加此信息可能会有所帮助。

我认为这是因为服务器关闭了数据库连接,或者数据库在池中时出现TCP超时。您使用的是哪个版本的asyncpg?您可以添加如何连接数据库吗?您是否尝试使用纯uvicorn而不是使用uvicornWorkers运行?您找到了此问题的答案吗?
autocannon -c 100 -d 40 -p 10 localhost:8000/shorten -H "Content-Type: application/json" -m POST -b '{"url": "http://yigitgenc.com"}'