Unexpected CancelledError
mheppner opened this issue · 2 comments
mheppner commented
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 commented
mheppner commented
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.