From 4c294965f255426542c133c3f55296a2837c3dbc Mon Sep 17 00:00:00 2001 From: Ricel Leite Date: Thu, 19 Feb 2026 00:22:37 -0300 Subject: [PATCH] fix: add pool_pre_ping and pool_recycle to prevent connection errors --- app/core/database.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/core/database.py b/app/core/database.py index 20a302f..151a750 100644 --- a/app/core/database.py +++ b/app/core/database.py @@ -6,7 +6,14 @@ from .config import settings # Convert sync URL to async DATABASE_URL = settings.DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://") -engine = create_async_engine(DATABASE_URL, echo=settings.DEBUG, pool_size=10, max_overflow=20) +engine = create_async_engine( + DATABASE_URL, + echo=settings.DEBUG, + pool_size=10, + max_overflow=20, + pool_pre_ping=True, # Test connection before using + pool_recycle=3600 # Recycle connections after 1 hour +) async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) Base = declarative_base()