From 57583c05cf0a4e083801e375421ded77f44e113f Mon Sep 17 00:00:00 2001 From: ThomasV Date: Tue, 1 Feb 2022 09:37:01 +0100 Subject: [PATCH] request_force_close: add 1s delay before closing the tranport, so that the remote task does not get cancelled. --- electrum/lnworker.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/electrum/lnworker.py b/electrum/lnworker.py index 481944917..e5d75d52b 100644 --- a/electrum/lnworker.py +++ b/electrum/lnworker.py @@ -2268,15 +2268,20 @@ class LNWallet(LNWorker): peer_addr = LNPeerAddr(host, port, node_id) transport = LNTransport(privkey, peer_addr, proxy=self.network.proxy) peer = Peer(self, node_id, transport, is_channel_backup=True) + async def trigger_force_close_and_wait(): + # wait before closing the transport, so that + # remote has time to process the message. + await peer.trigger_force_close(channel_id) + await asyncio.sleep(1) + peer.transport.close() try: async with OldTaskGroup(wait=any) as group: await group.spawn(peer._message_loop()) - await group.spawn(peer.trigger_force_close(channel_id)) + await group.spawn(trigger_force_close_and_wait()) return except Exception as e: self.logger.info(f'failed to connect {host} {e}') continue - # TODO close/cleanup the transport else: raise Exception('failed to connect')