From c1f39aceff206a61127b13ce0104087a6d35d9ed Mon Sep 17 00:00:00 2001 From: jaehwang Date: Mon, 18 May 2026 13:48:22 +0900 Subject: [PATCH] =?UTF-8?q?db=20connection=20pool=20bug=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/db.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/common/db.py b/app/common/db.py index 4b9307b..fea6634 100644 --- a/app/common/db.py +++ b/app/common/db.py @@ -15,23 +15,30 @@ async def get_pool() -> aiomysql.Pool: user=get_env("MYSQL_USER"), password=get_env("MYSQL_PASSWORD"), db=get_env("MYSQL_DB"), - autocommit=True, charset="utf8mb4", + minsize=0, + maxsize=30, + connect_timeout=10, ) return _pool +# 쓰기 (INSERT/UPDATE/DELETE) async def execute(sql: str, args: tuple = ()) -> int: pool = await get_pool() async with pool.acquire() as conn: + await conn.ping(reconnect=True) async with conn.cursor() as cur: await cur.execute(sql, args) + await conn.commit() return cur.lastrowid +# 읽기 (SELECT) async def fetchone(sql: str, args: tuple = ()) -> dict | None: pool = await get_pool() async with pool.acquire() as conn: + await conn.ping(reconnect=True) async with conn.cursor(aiomysql.DictCursor) as cur: await cur.execute(sql, args) return await cur.fetchone()