Skip to content

RuntimeError on page refresh #265

Description

@FelixFunk

Environment

Python: 3.11
Quart: 0.19.6
Hypercorn: 0.17.3
Firefox: 132.0

CMD

hypercorn run_service:quart_app -w 3 -b 0.0.0.0:44444 --debug --certfile "../dev/ssl/cert.pem" --keyfile "../dev/ssl/key.pem"

Issue

Sometimes during a page refresh the internal process crashes with the following stacktrace:

2024-11-05 10:46:26,466 | ERROR: Task exception was never retrieved                         
future: <Task finished name='Task-8321' coro=<ASGIHTTPConnection.handle_request() done, defined at `.venv/lib/python3.11/site-packages/quart/asgi.py:96> exception=RuntimeError('TaskGroup <TaskGroup cancelling> is finished') created at /usr/local/anaconda3/lib/python3.11/asyncio/tasks.py:670>                                                                                                            
source_traceback: Object created at (most recent call last):                          
  File "<string>", line 1, in <module>                                                                                                                              
  File "/usr/local/anaconda3/lib/python3.11/multiprocessing/spawn.py", line 122, in spawn_main                                                             
    exitcode = _main(fd, parent_sentinel)                                                                                                                   
  File "/usr/local/anaconda3/lib/python3.11/multiprocessing/spawn.py", line 135, in _main                                                         
    return self._bootstrap(parent_sentinel)                                                                                                                     
  File "/usr/local/anaconda3/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap                                                                 
    self.run()                          
  File "/usr/local/anaconda3/lib/python3.11/multiprocessing/process.py", line 108, in run                                                                       
    self._target(*self._args, **self._kwargs)                                                                                                               
  File ".venv/lib/python3.11/site-packages/hypercorn/asyncio/run.py", line 196, in asyncio_worker               
    _run(                               
  File ".venv/lib/python3.11/site-packages/hypercorn/asyncio/run.py", line 234, in _run                             
    runner.run(main(shutdown_trigger=shutdown_trigger))
  File "/usr/local/anaconda3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "/usr/local/anaconda3/lib/python3.11/asyncio/base_events.py", line 640, in run_until_complete
    self.run_forever()
  File "/usr/local/anaconda3/lib/python3.11/asyncio/base_events.py", line 607, in run_forever
    self._run_once()
  File "/usr/local/anaconda3/lib/python3.11/asyncio/base_events.py", line 1914, in _run_once
    handle._run()
  File "/usr/local/anaconda3/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File ".venv/lib/python3.11/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle
    await app(scope, receive, send, sync_spawn, call_soon)
  File ".venv/lib/python3.11/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
    await self.app(scope, receive, send)
  File ".venv/lib/python3.11/site-packages/quart/app.py", line 1667, in __call__
    await self.asgi_app(scope, receive, send)
  File ".venv/lib/python3.11/site-packages/quart/app.py", line 1693, in asgi_app
    await asgi_handler(receive, send)
  File ".venv/lib/python3.11/site-packages/quart/asgi.py", line 47, in __call__
    handler_task = asyncio.ensure_future(self.handle_request(request, send))
  File "/usr/local/anaconda3/lib/python3.11/asyncio/tasks.py", line 649, in ensure_future
    return _ensure_future(coro_or_future, loop=loop)
  File "/usr/local/anaconda3/lib/python3.11/asyncio/tasks.py", line 670, in _ensure_future
    return loop.create_task(coro_or_future) (base_events.py:1771)
Traceback (most recent call last):
  File ".venv/lib/python3.11/site-packages/quart/asgi.py", line 107, in handle_request
    await asyncio.wait_for(self._send_response(send, response), timeout=timeout)
  File "/usr/local/anaconda3/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/quart/asgi.py", line 142, in _send_response
    await send(
  File ".venv/lib/python3.11/site-packages/hypercorn/protocol/http_stream.py", line 200, in app_send
    await self._send_closed()
  File ".venv/lib/python3.11/site-packages/hypercorn/protocol/http_stream.py", line 247, in _send_closed
    await self.send(StreamClosed(stream_id=self.stream_id))
  File ".venv/lib/python3.11/site-packages/hypercorn/protocol/h2.py", line 230, in stream_send
    await self.send(Updated(idle=idle))
  File ".venv/lib/python3.11/site-packages/hypercorn/asyncio/tcp_server.py", line 90, in protocol_send
    await self.idle_task.restart(self._task_group, self._idle_timeout)
  File ".venv/lib/python3.11/site-packages/hypercorn/asyncio/worker_context.py", line 23, in restart
    self._handle = task_group._task_group.create_task(action())  # type: ignore
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/anaconda3/lib/python3.11/asyncio/taskgroups.py", line 159, in create_task
    raise RuntimeError(f"TaskGroup {self!r} is finished")
RuntimeError: TaskGroup <TaskGroup cancelling> is finished

In my current setup, this will always result in a closed websocket and therefore a disconnected service.

If there is anything i can do about it by adjusting the configuration of the webserver, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions