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

Unexpected CancelledError #79

Closed
mheppner opened this issue Apr 27, 2018 · 2 comments
Closed

Unexpected CancelledError #79

mheppner opened this issue Apr 27, 2018 · 2 comments

Comments

@mheppner
Copy link

I get errors coming from the aiomcache connection and I'm honestly not sure what the issue is. The aiohttp server sets up a connection when the app starts up:

# app.py
app = web.Application()
app.on_startup.append(tasks.start_memcached)
app.on_cleanup.append(tasks.stop_memcached)
# tasks.py
async def start_memcached(app):
    app['memcached'] = aiomcache.Client(host, port, loop=app.loop)

async def stop_memcached(app):
    app['memcached'].cancel()

Views that use the Client() instance will sometimes fail. I have a /health endpoint that is being checked every 30 seconds or so:

# views/health.py
async def health(request):
    is_healthy = False
    try:
        await request.app['memcached'].set(key, token)
        cache_response = await request.app['memcached'].get(key)
    except Exception:
        logger.exception('cannot connect to memcache')
    else:
        is_healthy = cache_response == token

    return web.json_response({'healthy': is_healthy})

The other requests that fail have the same traceback, but this is specifically the one from the health endpoint:

Traceback (most recent call last):
  File "/app/src/views/health.py", line 35, in health
    await cache.set(key, token)
  File "/usr/local/lib/python3.6/site-packages/aiomcache/client.py", line 20, in wrapper
    return (yield from func(self, conn, *args, **kwargs))
  File "/usr/local/lib/python3.6/site-packages/aiomcache/client.py", line 252, in set
    conn, b'set', key, value, flags, exptime)
  File "/usr/local/lib/python3.6/site-packages/aiomcache/client.py", line 232, in _storage_command
    resp = yield from self._execute_simple_command(conn, cmd)
  File "/usr/local/lib/python3.6/site-packages/aiomcache/client.py", line 68, in _execute_simple_command
    line = yield from conn.reader.readline()
  File "/usr/local/lib/python3.6/asyncio/streams.py", line 488, in readline
    line = yield from self.readuntil(sep)
  File "/usr/local/lib/python3.6/asyncio/streams.py", line 581, in readuntil
    yield from self._wait_for_data('readuntil')
  File "/usr/local/lib/python3.6/asyncio/streams.py", line 464, in _wait_for_data
    yield from self._waiter
concurrent.futures._base.CancelledError

There is nothing obvious in the memcached logs.

@asvetlov
Copy link
Member

@mheppner
Copy link
Author

mheppner commented May 1, 2018

Thank you, I used your aiojobs and it seems to have helped. Maybe a note about that section should go in the quickstart, I missed it in the advanced section. I'll reopen if I figure out if there actually is an issue with aiomcache.

@mheppner mheppner closed this as completed May 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants