From f505db4ac8a86a75ace0c283a3e740dd370f4b13 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Sun, 16 Nov 2025 02:15:01 +0100 Subject: [PATCH] fix: Reduce Drift SDK auto-reconnect interval from 4h to 2h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Bot froze after only 1 hour of runtime with API timeouts, despite having 4-hour auto-reconnect protection for Drift SDK memory leak. Investigation showed: - Singleton pattern working correctly (reusing same instance) - Hundreds of accountUnsubscribe errors (WebSocket leak) - Container froze at ~1 hour, not 4 hours Root Cause: Drift SDK's memory leak is MORE SEVERE than expected. Even with single instance, subscriptions accumulate faster than anticipated. 4-hour interval too long - system hits memory/connection limits before cleanup. Solution: Reduce auto-reconnect interval to 2 hours (more aggressive). This ensures cleanup happens before critical thresholds reached. Code change (lib/drift/client.ts): - reconnectIntervalMs: 4 hours → 2 hours - Updated log messages to reflect new interval Impact: System now self-heals every 2 hours instead of 4, preventing the freeze that occurred tonight at 1-hour mark. Related: Common Pitfall #1 (Drift SDK memory leak) --- lib/drift/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/drift/client.ts b/lib/drift/client.ts index cd4757c..7eeb56a 100644 --- a/lib/drift/client.ts +++ b/lib/drift/client.ts @@ -31,7 +31,7 @@ export class DriftService { private user: User | null = null private isInitialized: boolean = false private reconnectTimer: NodeJS.Timeout | null = null - private reconnectIntervalMs: number = 4 * 60 * 60 * 1000 // 4 hours (prevent memory leak) + private reconnectIntervalMs: number = 2 * 60 * 60 * 1000 // 2 hours (aggressive - Drift SDK memory leak is severe) constructor(private config: DriftConfig) { // Helius connection for Drift SDK initialization (handles burst subscriptions well) @@ -200,7 +200,7 @@ export class DriftService { clearTimeout(this.reconnectTimer) } - // Schedule reconnection every 4 hours + // Schedule reconnection every 2 hours this.reconnectTimer = setTimeout(async () => { try { console.log('🔄 Scheduled reconnection: Clearing WebSocket subscriptions to prevent memory leak...')