From 8b15d64dc980167d4ef8ea5cc0c5b3b13e1d896f Mon Sep 17 00:00:00 2001 From: f321x Date: Tue, 10 Jun 2025 13:49:47 +0200 Subject: [PATCH] fix: prevent KeyError if _fail_swap gets called multiple times If `_fail_swap()` gets called multiple times (e.g. from callbacks) this would race a `KeyError` as the swap got already popped from `self._swaps`. In theory `_fail_swap` unregisters itself from the lnwatcher callback but the callback may is scheduled multiple times before it has the chance to unregister itself. --- electrum/submarine_swaps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/electrum/submarine_swaps.py b/electrum/submarine_swaps.py index f9747fda3..d0305614c 100644 --- a/electrum/submarine_swaps.py +++ b/electrum/submarine_swaps.py @@ -361,7 +361,8 @@ class SwapManager(Logger): self.lnwatcher.remove_callback(swap.lockup_address) if not swap.is_funded(): with self.swaps_lock: - self._swaps.pop(swap.payment_hash.hex()) + if self._swaps.pop(swap.payment_hash.hex(), None) is None: + self.logger.debug(f"swap {swap.payment_hash.hex()} has already been deleted.") # TODO clean-up other swaps dicts, i.e. undo _add_or_reindex_swap() @classmethod