From 4f84dc6324ecf83f4fbc0013ffc9cea0e9bb515c Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 25 Jan 2026 13:28:28 +0300 Subject: [PATCH 1/4] Update database.py --- app/database/database.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/database/database.py b/app/database/database.py index 9ebb6715..0c2c99a4 100644 --- a/app/database/database.py +++ b/app/database/database.py @@ -41,7 +41,7 @@ else: pool_kwargs = { 'pool_size': 30, # Увеличен с 20 'max_overflow': 50, # Увеличен с 30 - 'pool_timeout': 30, + 'pool_timeout': 60, # Увеличен с 30 для обработки пиковых нагрузок 'pool_recycle': 1800, # Уменьшен с 3600 до 30 мин для более быстрого recycling 'pool_pre_ping': True, # Агрессивная очистка мертвых соединений @@ -61,7 +61,7 @@ _pg_connect_args = { 'idle_in_transaction_session_timeout': '300000', # 5 минут }, 'command_timeout': 60, - 'timeout': 30, # Увеличен с 10 до 30 сек для высокой нагрузки + 'timeout': 60, # Увеличен с 30 до 60 сек для обработки пиковых нагрузок } engine = create_async_engine( @@ -94,7 +94,7 @@ AsyncSessionLocal = async_sessionmaker( # RETRY LOGIC FOR DATABASE OPERATIONS # ============================================================================ -RETRYABLE_EXCEPTIONS = (OperationalError, InterfaceError, ConnectionRefusedError, OSError) +RETRYABLE_EXCEPTIONS = (OperationalError, InterfaceError, ConnectionRefusedError, OSError, TimeoutError) DEFAULT_RETRY_ATTEMPTS = 3 DEFAULT_RETRY_DELAY = 0.5 # секунды From b797a93105c168694d07cc597f40d01a527f5493 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 25 Jan 2026 13:28:59 +0300 Subject: [PATCH 2/4] Update notification_delivery_service.py --- app/services/notification_delivery_service.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/services/notification_delivery_service.py b/app/services/notification_delivery_service.py index 45637cab..08230c8d 100644 --- a/app/services/notification_delivery_service.py +++ b/app/services/notification_delivery_service.py @@ -191,14 +191,24 @@ class NotificationDeliveryService: try: from aiogram.exceptions import TelegramBadRequest, TelegramForbiddenError - await bot.send_message( - chat_id=user.telegram_id, - text=message, - reply_markup=markup, - parse_mode='HTML', + await asyncio.wait_for( + bot.send_message( + chat_id=user.telegram_id, + text=message, + reply_markup=markup, + parse_mode='HTML', + ), + timeout=15.0, ) return True + except asyncio.TimeoutError: + logger.warning( + 'Timeout при отправке Telegram уведомления пользователю %s', + user.telegram_id, + ) + return False + except TelegramForbiddenError: logger.warning( 'Telegram user %s заблокировал бота', From af45f1aac01ee7578d78d6763a82949b68580dc4 Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 25 Jan 2026 13:29:26 +0300 Subject: [PATCH 3/4] Update dependencies.py --- app/cabinet/dependencies.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/cabinet/dependencies.py b/app/cabinet/dependencies.py index e3ff5c14..2bc626b2 100644 --- a/app/cabinet/dependencies.py +++ b/app/cabinet/dependencies.py @@ -1,5 +1,6 @@ """FastAPI dependencies for cabinet module.""" +import asyncio import logging from aiogram import Bot @@ -129,7 +130,10 @@ async def get_current_cabinet_user( if not is_admin: try: bot = _get_channel_check_bot() - chat_member = await bot.get_chat_member(chat_id=settings.CHANNEL_SUB_ID, user_id=user.telegram_id) + chat_member = await asyncio.wait_for( + bot.get_chat_member(chat_id=settings.CHANNEL_SUB_ID, user_id=user.telegram_id), + timeout=10.0, + ) # Не закрываем сессию - бот переиспользуется if chat_member.status not in ['member', 'administrator', 'creator']: @@ -143,6 +147,9 @@ async def get_current_cabinet_user( ) except HTTPException: raise + except asyncio.TimeoutError: + logger.warning(f'Timeout checking channel subscription for user {user.telegram_id}') + # Don't block user if check times out except Exception as e: logger.warning(f'Failed to check channel subscription for user {user.telegram_id}: {e}') # Don't block user if check fails From 99c60793b8ae0bd89bdf740f25042b27f9c5c71d Mon Sep 17 00:00:00 2001 From: Egor Date: Sun, 25 Jan 2026 13:29:52 +0300 Subject: [PATCH 4/4] Update remnawave_api.py --- app/external/remnawave_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/external/remnawave_api.py b/app/external/remnawave_api.py index 4294f188..6766a5ef 100644 --- a/app/external/remnawave_api.py +++ b/app/external/remnawave_api.py @@ -341,7 +341,7 @@ class RemnaWaveAPI: connector = aiohttp.TCPConnector(**connector_kwargs) - session_kwargs = {'timeout': aiohttp.ClientTimeout(total=30), 'headers': headers, 'connector': connector} + session_kwargs = {'timeout': aiohttp.ClientTimeout(total=60, connect=10), 'headers': headers, 'connector': connector} if cookies: session_kwargs['cookies'] = cookies