hypercorn
hypercorn copied to clipboard
Unexpected "shutdown without Lifespan support" error on Hypercorn 0.17.3
MCVE:
import trio
from quart_trio import QuartTrio
from exceptiongroup import catch
app = QuartTrio(__name__)
@app.route('/')
async def data():
return {}
async def serve():
async with trio.open_nursery() as nursery:
nursery.start_soon(app.run_task, "0.0.0.0", 5007, False)
async def run():
def handle_stop(_):
nonlocal nursery
print("\nStopping...")
nursery.cancel_scope.cancel()
with catch({
KeyboardInterrupt: handle_stop,
}):
async with trio.open_nursery() as nursery:
nursery.start_soon(serve)
trio.run(run)
On Hypercorn 0.17.3, when I press Ctrl-C, this happens:
2024-05-30 12:34:24 +0900] [59521] [INFO] Running on http://0.0.0.0:5007 (CTRL + C to quit)
^C[2024-05-30 12:34:24 +0900] [59521] [ERROR] ASGI Framework Lifespan error, shutdown without Lifespan support
+ Exception Group Traceback (most recent call last):
| File "<venv>/lib/python3.10/site-packages/hypercorn/trio/lifespan.py", line 41, in handle_lifespan
| await self.app(
| File "<venv>/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
| await self.app(scope, receive, send)
| File "<venv>/lib/python3.10/site-packages/quart/app.py", line 1667, in __call__
| await self.asgi_app(scope, receive, send)
| File "<venv>/lib/python3.10/site-packages/quart/app.py", line 1693, in asgi_app
| await asgi_handler(receive, send)
| File "<venv>/lib/python3.10/site-packages/quart_trio/asgi.py", line 126, in __call__
| async with trio.open_nursery() as nursery:
| File "<venv>/lib/python3.10/site-packages/trio/_core/_run.py", line 963, in __aexit__
| raise combined_error_from_nursery
| exceptiongroup.BaseExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<venv>/lib/python3.10/site-packages/quart_trio/asgi.py", line 129, in __call__
| event = await receive()
| File "<venv>/lib/python3.10/site-packages/hypercorn/trio/lifespan.py", line 98, in asgi_receive
| return await self.app_receive_channel.receive()
| File "<venv>/lib/python3.10/site-packages/trio/_channel.py", line 356, in receive
| return await trio.lowlevel.wait_task_rescheduled(abort_fn) # type: ignore[no-any-return]
| File "<venv>/lib/python3.10/site-packages/trio/_core/_traps.py", line 179, in wait_task_rescheduled
| return (await _async_yield(WaitTaskRescheduled(abort_func))).unwrap()
| File "<venv>/lib/python3.10/site-packages/outcome/_impl.py", line 213, in unwrap
| raise captured_error
| File "<venv>/lib/python3.10/site-packages/trio/_core/_run.py", line 1453, in raise_cancel
| raise Cancelled._create()
| trio.Cancelled: Cancelled
+------------------------------------
The environment is Python3.10 with the following packages, installed just using pip install quart_trio:
aiofiles==23.2.1
attrs==23.2.0
blinker==1.8.2
click==8.1.7
exceptiongroup==1.2.1
Flask==3.0.3
h11==0.14.0
h2==4.1.0
hpack==4.0.0
Hypercorn==0.17.3
hyperframe==6.0.1
idna==3.7
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==2.1.5
outcome==1.3.0.post0
priority==2.0.0
Quart==0.19.6
quart-trio==0.11.1
sniffio==1.3.1
sortedcontainers==2.4.0
taskgroup==0.0.0a4
tomli==2.0.1
trio==0.25.1
typing_extensions==4.12.0
Werkzeug==3.0.3
wsproto==1.2.0
Hypercorn 0.17.2 exhibits the intended behaviour:
$ pip uninstall -y hypercorn==0.17.3
$ pip install hypercorn==0.17.2
$ python test.py
[2024-05-30 12:42:33 +0900] [62968] [INFO] Running on http://0.0.0.0:5007 (CTRL + C to quit)
^C
Stopping...
$
Should be fixed by 4cf352890e6869bfbc0940e75420ea897fa92518
It is.
Do you plan to do a new release sometime soon? This one really trips me at the moment …