From f5eb369fb71ba82c41908df27b6ee90baf99ba78 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Sat, 16 Mar 2019 21:20:14 +0100 Subject: [PATCH] lnpeer: spawn wait_for(self.initialized) to kill the TaskGroup if it times out --- electrum/lnpeer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/electrum/lnpeer.py b/electrum/lnpeer.py index 2d7bd415e..ea5c49247 100644 --- a/electrum/lnpeer.py +++ b/electrum/lnpeer.py @@ -205,13 +205,14 @@ class Peer(PrintError): return wrapper_func @ignore_exceptions # do not kill main_taskgroup - @log_exceptions @handle_disconnect async def main_loop(self): async with aiorpcx.TaskGroup() as group: await group.spawn(self._gossip_loop()) await group.spawn(self._message_loop()) + await group.spawn(asyncio.wait_for(self.initialized.wait(), 10)) + @log_exceptions async def _gossip_loop(self): await self.initialized.wait() while True: @@ -229,7 +230,11 @@ class Peer(PrintError): if need_to_get and not self.receiving_channels: self.print_error('QUERYING SHORT CHANNEL IDS; missing', len(need_to_get), 'channels') zlibencoded = zlib.compress(bfh(''.join(need_to_get))) - self.send_message('query_short_channel_ids', chain_hash=bytes.fromhex(bitcoin.rev_hex(constants.net.GENESIS)), len=1+len(zlibencoded), encoded_short_ids=b'\x01' + zlibencoded) + self.send_message( + 'query_short_channel_ids', + chain_hash=bytes.fromhex(bitcoin.rev_hex(constants.net.GENESIS)), + len=1+len(zlibencoded), + encoded_short_ids=b'\x01' + zlibencoded) self.receiving_channels = True async def _message_loop(self): @@ -238,7 +243,6 @@ class Peer(PrintError): except (OSError, asyncio.TimeoutError, HandshakeFailed) as e: self.print_error('initialize failed, disconnecting: {}'.format(repr(e))) return - # loop async for msg in self.transport.read_messages(): self.process_message(msg) await asyncio.sleep(.01)