aio-libs / aiomcache

Minimal asyncio memcached client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

connection does not close

kikdevops opened this issue · comments

Hi.
I'm trying to write a key with a value in the memcached server but the client connection is not closed. I use this functions in aiohttp.web.Application.
`

async def mc_write(key, an):
    mc = aiomcache.Client("memcached", 11211)
    await mc.set(key.encode(encoding='UTF-8'), an.encode(encoding='UTF-8'))
    mc.close()

async def Handler(body, headers, key, url):
    logging.info("Start processing key: {}".format(key))

    try:
        async with aiohttp.ClientSession() as session:
            async with session.post(url, data=body, headers=headers) as resp:
                an = await resp.text()
                end = time.time()
    except Exception as e:
        return e

#Send result to memcache
    await mc_write(key, an)`

On memcached server i see lots of connections:
``
lsof -p 1 | grep ESTABLISHED | wc -l

12
``
What I'm do wrong, how I can close connections?

My bad
await mc.close()
solve issue