fix: clean up fight event listeners after completion (BUG-12)

Move fightEvents.cleanup(fightId) to finally block to ensure
cleanup runs even if post-fight operations (bets, payouts) fail.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 08:39:42 +00:00
co-authored by Claude Opus 4.6
parent 0f606cc991
commit 0f95cbf881
+3 -1
View File
@@ -555,6 +555,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
potSats: mode === 'ranked' ? 42 : 0, potSats: mode === 'ranked' ? 42 : 0,
}) })
try {
// Publish notable results to Nostr // Publish notable results to Nostr
if (winnerId) { if (winnerId) {
const winner = winnerId === botA.id ? botA : botB const winner = winnerId === botA.id ? botA : botB
@@ -608,9 +609,10 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
} }
} }
} }
} finally {
fightEvents.cleanup(fightId) fightEvents.cleanup(fightId)
} }
}
export async function runFight(botAId: string, botBId: string, mode: 'free' | 'ranked' = 'free'): Promise<string> { export async function runFight(botAId: string, botBId: string, mode: 'free' | 'ranked' = 'free'): Promise<string> {
if (botAId === botBId) throw new Error('A bot cannot fight itself') if (botAId === botBId) throw new Error('A bot cannot fight itself')