emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.86k stars 83 forks source link

RuntimeError: ASGI transport was closed #96

Closed ameyer117 closed 1 year ago

ameyer117 commented 1 year ago

I'm getting the following error when using Granian (0.5.0) with Django (4.2.2). This error does not appear to occur with version 0.4.3 of Granian. It also doesn't seem to break functionality, the web server still serves the page, but these errors appear on nearly every request. Additionally, if it helps, I'm running this via docker with a RHEL-8-UBI image. Let me know if there are any further details I can provide & thank you for creating such a wonderful server!

webapp-app-1       | Task exception was never retrieved
webapp-app-1       | future: <Task finished name='Task-11' coro=<future_watcher_wrapper.<locals>.future_watcher() done, defined at /usr/local/lib/python3.11/site-packages/granian/_futures.py:2> exception=RuntimeError('ASGI transport closed')>
webapp-app-1       | Traceback (most recent call last):
webapp-app-1       |   File "/usr/local/lib/python3.11/site-packages/granian/_futures.py", line 4, in future_watcher
webapp-app-1       |     await inner(watcher.scope, watcher.proto)
webapp-app-1       |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 160, in __call__
webapp-app-1       |     await self.handle(scope, receive, send)
webapp-app-1       |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 190, in handle
webapp-app-1       |     await self.send_response(response, send)
webapp-app-1       |   File "/usr/local/lib/python3.11/site-packages/django/core/handlers/asgi.py", line 284, in send_response
webapp-app-1       |     await send({"type": "http.response.body"})
webapp-app-1       | RuntimeError: ASGI transport closed
webapp-app-1       | Application callable raised an exception
gi0baro commented 1 year ago

@ameyer117 I wasn't able to reproduce the issue.

I still have made a change in https://github.com/emmett-framework/granian/commit/d127424eecbdd4dc49e3165eae3d1af436c13b5d to avoid tx in ASGI I/O when body is empty to avoid prompting errors in such case.

Will be released in 0.5.1 shortly, gonna keep this open until that.

ameyer117 commented 1 year ago

@gi0baro - thank you!