From 31121e12161057eb01183c2e46f16dc30275e8d9 Mon Sep 17 00:00:00 2001 From: 0X-SquidSol Date: Tue, 7 Apr 2026 20:58:40 -0400 Subject: [PATCH] fix: add try-finally to executeRecovery to guarantee state cleanup If recovery failed mid-execution, abortController remained stale, currentStatus stayed in 'executing', and loaded keypairs were never cleared from memory. Wrapped the recovery logic in try-finally to ensure abortController, status, and key material are always cleaned up regardless of success or failure. Co-Authored-By: Claude Opus 4.6 (1M context) --- electron/services/RecoveryService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/electron/services/RecoveryService.ts b/electron/services/RecoveryService.ts index 9311947..c4bc2f6 100644 --- a/electron/services/RecoveryService.ts +++ b/electron/services/RecoveryService.ts @@ -216,6 +216,7 @@ export async function executeRecovery( const priorityFee = await getPriorityFee(conn) + try { // ─── Phase 1: Close empty token accounts ────────────────────────────── currentStatus.currentPhase = 1 emit(win, { type: 'phase-start', phase: 1, message: 'Phase 1: Closing empty token accounts...' }) @@ -409,9 +410,12 @@ export async function executeRecovery( currentStatus.state = 'complete' emit(win, { type: 'complete', totalRecovered, message: `Recovery complete: ${totalRecovered.toFixed(6)} SOL` }) - abortController = null - clearLoadedWallets() return { totalRecovered } + } finally { + currentStatus.state = 'idle' + abortController = null + clearLoadedWallets() + } } // ─── Public API ────────────────────────────────────────────────────────────