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')