commit f5eb369fb71ba82c41908df27b6ee90baf99ba78
parent 2c80996fbf23b612e58e73ff727c2bae1d782e34
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 16 Mar 2019 21:20:14 +0100
lnpeer: spawn wait_for(self.initialized) to kill the TaskGroup if it times out
Diffstat:
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git 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)