1
0

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.
This commit is contained in:
f321x
2025-06-10 13:49:47 +02:00
parent 660b97c906
commit 8b15d64dc9

View File

@@ -361,7 +361,8 @@ class SwapManager(Logger):
self.lnwatcher.remove_callback(swap.lockup_address) self.lnwatcher.remove_callback(swap.lockup_address)
if not swap.is_funded(): if not swap.is_funded():
with self.swaps_lock: 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() # TODO clean-up other swaps dicts, i.e. undo _add_or_reindex_swap()
@classmethod @classmethod