Open nabheet opened 5 months ago
I have a similar-looking issue: when I use DispatcherMiddleware
to run a Quart app that uses before_serving
(with only the one app in the routes), and the before_serving
method throws an exception, the exception is logged, the server hangs (not responding to anything except SIGKILL) for several seconds, and then I get the same chain of CancelledError / TimeoutError / LifespanTimeoutError. When DispatcherMiddleware
isn't involved, the program immediately terminates as expected.
Aside from the issue when a startup routine throws an exception, when I use DispatcherMiddleware
wrapping the one app and exit the server with Ctrl-C, I receive this error:
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File ".../__main__.py", line 69, in <module>
asyncio.run(serve(dispatcher, config))
File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/asyncio/base_events.py", line 664, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.12/site-packages/hypercorn/asyncio/__init__.py", line 44, in serve
await worker_serve(
File ".../.venv/lib/python3.12/site-packages/hypercorn/asyncio/run.py", line 181, in worker_serve
await lifespan_task
File ".../.venv/lib/python3.12/site-packages/hypercorn/asyncio/lifespan.py", line 55, in handle_lifespan
await self.app(
File ".../.venv/lib/python3.12/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
await self.app(scope, receive, send)
File ".../src/connector/__main__.py", line 57, in __call__
await self.app(scope, receive, send)
File ".../.venv/lib/python3.12/site-packages/hypercorn/middleware/dispatcher.py", line 19, in __call__
await self._handle_lifespan(scope, receive, send)
File ".../.venv/lib/python3.12/site-packages/hypercorn/middleware/dispatcher.py", line 46, in _handle_lifespan
async with TaskGroup(asyncio.get_event_loop()) as task_group:
File ".../.venv/lib/python3.12/site-packages/hypercorn/asyncio/task_group.py", line 74, in __aexit__
await self._task_group.__aexit__(exc_type, exc_value, tb)
File "/usr/lib/python3.12/asyncio/taskgroups.py", line 136, in __aexit__
raise propagate_cancellation_error
File "/usr/lib/python3.12/asyncio/taskgroups.py", line 112, in __aexit__
await self._on_completed_fut
asyncio.exceptions.CancelledError
No such error occurs when not using DispatcherMiddleware
.
Hi,
I am not sure if our use case is supported. We have FastAPI application that exposes our core API. I am hoping to add the RQ Dashboard to the same API but at
/rq
path. When I use the Dispatcher middleware, Hypercorn reports a timeout exception. However, if I try to only start the Flash app that is wrapped inAsyncioWSGIMiddleware
, it starts up correctly.install packages (we use pipenv, I am assuming you can replace it with pip easily)
Here is the minimal code to reproduce the issue:
This works:
This does not:
Please advise on how best to proceed.