stability

This commit is contained in:
Dobromir Popov
2025-08-08 17:32:09 +03:00
parent 78b96c10af
commit f8d3e1c999
4 changed files with 35 additions and 14 deletions

View File

@ -175,6 +175,11 @@ class EnhancedCOBWebSocket:
async def start(self):
"""Start COB WebSocket connections"""
logger.info("Starting Enhanced COB WebSocket system")
# Idempotence guard: avoid spawning duplicate tasks if already started
if any(task for task in self.websocket_tasks.values() if task and not task.done()):
logger.warning("Enhanced COB WebSocket already started - skipping duplicate start")
return
# Initialize REST session for fallback
await self._init_rest_session()
@ -386,9 +391,12 @@ class EnhancedCOBWebSocket:
await self._start_rest_fallback(symbol)
return
# Cancel existing task if running
if symbol in self.websocket_tasks and not self.websocket_tasks[symbol].done():
self.websocket_tasks[symbol].cancel()
# If a task exists and is still running, do not spawn another
if symbol in self.websocket_tasks:
existing = self.websocket_tasks[symbol]
if existing and not existing.done():
logger.warning(f"WebSocket task already running for {symbol} - skipping restart")
return
# Start new WebSocket task
self.websocket_tasks[symbol] = asyncio.create_task(