aio-libs / aio-libs/aiocache

Potential memory leak/bug in the valkey client

オープン
#1,023 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
1.4k
フォーク
181
PR マージ指標
30日以内にマージされた PR はありません

説明

I think there might be an issue with the `__aenter__` method on the ValkeyBackend.
https://github.com/aio-libs/aiocache/blob/d685fff3303138eb466a69bb5dbb4d6a345ef1ae/aiocache/backends/valkey.py#L32-L37

This code snippet explains my thinking.
```
async def cache_operations():
client_1 = None
async with ValkeyCache(
config=GlideClientConfiguration(addresses=[NodeAddress("localhost", 6379)])
) as my_cache_1: # <<< new client created
client_1 = my_cache_1.client
async with my_cache_1 as my_cache_2: # <<< new client created
assert my_cache_1 is my_cache_2 # because of return self
client_2 = my_cache_2
assert client_1 != client_2
assert my_cache_1.client == client_2
# exit inner with, call __aexit__, calls await self.client.close(); i.e. client_2.close())
assert my_cache_1.client != client_1 # it's still client_2
# exit inner with, call __aexit__, calls await self.client.close(); i.e. client_2.close() again, which may error.
# client_1.close() may never be called
```
I think that the `__aenter__` method should maybe handle checking if an existing connection is available and disposing of it if not, or else return a clone of `self` with a new client to ensure that the connection does get managed correctly.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。