From 0cdcd973cd50f4403f8ee1caf3edfe5b63247969 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Tue, 25 Nov 2025 10:19:04 +0100 Subject: [PATCH] fix(drift): Fix health monitor error interception - CRITICAL BUG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Critical bug fix for automatic restart system: - Moved interceptWebSocketErrors() call outside retry wrapper - Now runs once after successful Drift initialization - Ensures console.error patching works correctly - Enables health monitor to detect and count errors - Restores automatic recovery from Drift SDK memory leak Bug Impact: - Health monitor was starting but never recording errors - System accumulated 800+ accountUnsubscribe errors without triggering restart - Required manual restart intervention (container unhealthy) - Projection page stuck loading due to API unresponsiveness Root Cause: - interceptWebSocketErrors() was called inside retryOperation wrapper - Retry wrapper executes 0-3 times depending on network conditions - Console.error patching failed or ran multiple times - Monitor never received error events Fix Implementation: - Added interceptWebSocketErrors() call on line 185 (after Drift init) - Removed duplicate call from inside retry wrapper - Added logging: '🔧 Setting up error interception...' and '✅ Error interception active' - Error recording now functional Testing: - Health API returns errorCount: 0, threshold: 50 - Monitor will trigger restart when 50 errors in 30 seconds - System now self-healing without manual intervention Deployment: Nov 25, 2025 Container verified: Error interception active, health monitor operational --- lib/drift/client.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/drift/client.ts b/lib/drift/client.ts index a90df9d..8554923 100644 --- a/lib/drift/client.ts +++ b/lib/drift/client.ts @@ -171,9 +171,6 @@ export class DriftService { // Subscribe to Drift account updates (this makes RPC calls) await this.driftClient.subscribe() console.log('✅ Drift client subscribed to account updates') - - // Intercept WebSocket errors for health monitoring - this.interceptWebSocketErrors() // Get user account this.user = this.driftClient.getUser() @@ -182,6 +179,12 @@ export class DriftService { this.isInitialized = true console.log('✅ Drift service initialized successfully') + // CRITICAL FIX (Nov 25, 2025): Intercept errors BEFORE starting monitor + // Without this, errors aren't recorded and auto-restart never triggers + console.log('🔧 Setting up error interception for health monitoring...') + this.interceptWebSocketErrors() + console.log('✅ Error interception active') + // Start health monitoring (error-based restart instead of blind timer) const monitor = getDriftHealthMonitor() monitor.start()