Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sgentle opened this issue Jan 7, 2019 · 3 comments · Fixed by #3500
Closed

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

sgentle opened this issue Jan 7, 2019 · 3 comments · Fixed by #3500

Comments

@sgentle
Copy link

sgentle commented Jan 7, 2019

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
@aio-libs-bot
Copy link

GitMate.io thinks the contributor most likely able to help you is @asvetlov.

Possibly related issues are #3242 (Error), #1745 (Call https website through proxy will cause error), #816 (Logging error), #1839 (aiohttp webserver with python 3.7 broken), and #429 (Websocket error).

@asvetlov
Copy link
Member

asvetlov commented Jan 8, 2019

Thanks for the report.
I've committed the difference into asyncio but forgot about the behavior change on working on aiohttp.

asvetlov added a commit that referenced this issue Jan 8, 2019
asvetlov added a commit that referenced this issue Jan 8, 2019
* Fix #3497: Ignore done tasks when cancels pending activities on web.run_app finalization.
asvetlov added a commit that referenced this issue Jan 8, 2019
* Fix #3497: Ignore done tasks when cancels pending activities on web.run_app finalization.
(cherry picked from commit 4e99e81)

Co-authored-by: Andrew Svetlov <[email protected]>
asvetlov added a commit that referenced this issue Jan 8, 2019
* Fix #3497: Ignore done tasks when cancels pending activities on web.run_app finalization.
(cherry picked from commit 4e99e81)

Co-authored-by: Andrew Svetlov <[email protected]>
@lock
Copy link

lock bot commented Jan 8, 2020

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Jan 8, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants