Skip to content

web._cancel_all_tasks causes spurious errors on Python <3.7 #3497

Closed
@sgentle

Description

Long story short

Python 3.5's asyncio.Task.all_tasks differs from Python 3.7's asyncio.all_tasks in that it includes completed tasks. However, the all_tasks helper uses them interchangeably.

This means that when you shutdown a server started with web.run_app on Python 3.5 or 3.6, failed requests are rethrown as exceptions in web._cancel_all_tasks, whether they were handled or not.

Steps to reproduce

  1. python3.5 -c 'from aiohttp import web; web.run_app(web.Application())'
  2. visit http://localhost:8080
  3. ctrl+c the server

Expected behaviour

Actual behaviour

unhandled exception during asyncio.run() shutdown
task: <Task finished coro=<Application._handle() done, defined at /usr/lib/python3.5/site-packages/aiohttp/web_app.py:405> exception=<HTTPNotFound Not Found eof>
  File "/usr/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 406, in start
    resp = await task
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/lib/python3.5/site-packages/aiohttp/web_app.py", line 435, in _handle
    resp = await handler(request)
  File "/usr/lib/python3.5/site-packages/aiohttp/web_urldispatcher.py", line 848, in _handle
    raise self._http_exception
aiohttp.web_exceptions.HTTPNotFound: Not Found

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions