uvicorn: RuntimeError in uvicorn for some requests
uvicorn==0.2.5 is throwing errors for some requests.
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/uvicorn/protocols/http/httptools.py", line 196, in run_asgi
result = await asgi(self.receive, self.send)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/channels/http.py", line 190, in __call__
await self.handle(body)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/asgiref/sync.py", line 110, in __call__
return await asyncio.wait_for(future, timeout=None)
File "/usr/lib/python3.6/asyncio/tasks.py", line 339, in wait_for
return (yield from fut)
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/asgiref/sync.py", line 125, in thread_handler
return self.func(*args, **kwargs)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/channels/http.py", line 229, in handle
self.send(response_message)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/asgiref/sync.py", line 64, in __call__
return call_result.result()
File "/usr/lib/python3.6/concurrent/futures/_base.py", line 432, in result
return self.__get_result()
File "/usr/lib/python3.6/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/asgiref/sync.py", line 78, in main_wrap
result = await self.awaitable(*args, **kwargs)
File "/home/chillar/.virtualenvs/library/lib/python3.6/site-packages/uvicorn/protocols/http/httptools.py", line 308, in send
protocol.transport.write(body)
File "uvloop/handles/stream.pyx", line 636, in uvloop.loop.UVStream.write
File "uvloop/handles/handle.pyx", line 165, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x1a48ad8>; the handler is closed
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 35 (15 by maintainers)
Commits related to this issue
- Try to circuvent fastapi strange error https://github.com/encode/uvicorn/issues/111 — committed to alramalho/ask-paper-ai by alramalho a year ago
For the commenters above - if the following applies to you:
FastAPI<0.87.0definstead ofasync def…then you may be susceptible to https://github.com/encode/starlette/issues/919, which can cause these errors in uvicorn:
LocalProtocolError: Can't send data when our state is ERRORLocalProtocolError: can't handle event type ConnectionClosed when role=SERVER and state=SEND_RESPONSEThis issue was resolved in
starlette==0.21.0, which was added inFastAPI==0.87.0. Bumping toFastAPI>=0.87.0should fix your application.Apologies for responding to an old issue, this page is the top search result for the above errors.
@Kludex Happy to investigate this issue if it still needs attention!
FYI I am getting this error with uvicorn 0.11.5 and h11 0.9.0, on a Django channels project. I’m running uvicorn with just the basic host/port options. The error happens only sometimes and has not had any impact on my app’s functionality.
Happy to provide extra info.
@r1b I am still getting this error when trying to test
defendpoint with ~50 users concurrency. Do you have any idea why? FastAPI==0.92.0Update: After removing middleware I don’t see this issue. Does anyone has ideas why it breaks the server?
@euri10 the error is gone in the latest master, thank you! 👍
(I am still getting this issue: https://github.com/encode/uvicorn/issues/757 but will continue the discussion over there.)
This issue was resolved years ago, and there’s too much information here.
If interested, please open a discussion with a minimal reproducible example.
Fixed by #832 it seems !😎
Released as 0.2.6