Skip to content

Lots of CancelledError when requests are interupted #1565

Closed
@samuelcolvin

Description

Long story short

aiohttp barfs out hundreds of concurrent.futures._base.CancelledError when requests are interrupted.

Expected behaviour

Not sure, I guess we can't just ignore CancelledError in requests but it would be good if there was some way to stop loads of errors being printed.

This is annoying in the terminal but could cause a major backlog if sentry etc. were connected and processing exceptions.

You can catch and ignore this error with middleware:

async def cancelled_error_middleware(app, handler):
    async def _handler(request):
        try:
            return await handler(request)
        except CancelledError:
            raise HTTPBadRequest()
    return _handler

But I'm not sure how safe this is?

Actual behaviour

[2017-01-30 12:22:19 +0000] [30723] [ERROR] Error handling request
Traceback (most recent call last):
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiohttp/web_server.py", line 61, in handle_request
    resp = yield from self._handler(request)
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiohttp/web.py", line 249, in _handle
    resp = yield from handler(request)
  File "/home/vagrant/FrameworkBenchmarks/frameworks/Python/aiohttp/app/views.py", line 142, in updates
    .values(randomnumber=randint(1, 10000))
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiopg/utils.py", line 72, in __await__
    resp = yield from self._coro
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiopg/sa/connection.py", line 110, in _execute
    yield from cursor.execute(str(compiled), post_processed_params[0])
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiopg/cursor.py", line 113, in execute
    yield from self._conn._poll(waiter, timeout)
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiopg/connection.py", line 240, in _poll
    raise exc
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/site-packages/aiopg/connection.py", line 237, in _poll
    yield from asyncio.wait_for(self._waiter, timeout, loop=self._loop)
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/asyncio/tasks.py", line 379, in wait_for
    yield from waiter
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/asyncio/futures.py", line 358, in __iter__
    yield self  # This tells Task to wait for completion.
  File "uvloop/future.pyx", line 434, in uvloop.loop.BaseTask._fast_wakeup (uvloop/loop.c:114015)
  File "/home/vagrant/FrameworkBenchmarks/installs/py3/lib/python3.5/asyncio/futures.py", line 266, in result
    raise CancelledError
concurrent.futures._base.CancelledError

Coming through thousands of times as I run wrk load tests. I suspect the same would occur with ajax interrupted requests or even browsers stopping a request if a new one is requested.

Steps to reproduce

wrk -t12 -c100 -d10s http://localhost:8000/whatever

While running your aiohttp application with gunicorn.

Your environment

Ubuntu.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions