From 975e9c5369fb42511c5887ccee5b2fe034af47c6 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Wed, 7 Jul 2021 02:22:12 -0400 Subject: [PATCH] Wait for open connection on startup --- matrix_puppeteer_line/rpc/rpc.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/matrix_puppeteer_line/rpc/rpc.py b/matrix_puppeteer_line/rpc/rpc.py index 83db369..56de9e8 100644 --- a/matrix_puppeteer_line/rpc/rpc.py +++ b/matrix_puppeteer_line/rpc/rpc.py @@ -60,10 +60,22 @@ class RPCClient: return if self.config["puppeteer.connection.type"] == "unix": - r, w = await asyncio.open_unix_connection(self.config["puppeteer.connection.path"]) + while True: + try: + r, w = await asyncio.open_unix_connection(self.config["puppeteer.connection.path"]) + break + except: + self.log.warn(f'No unix socket available at {self.config["puppeteer.connection.path"]}, wait for it to exist...') + await asyncio.sleep(10) elif self.config["puppeteer.connection.type"] == "tcp": - r, w = await asyncio.open_connection(self.config["puppeteer.connection.host"], - self.config["puppeteer.connection.port"]) + while True: + try: + r, w = await asyncio.open_connection(self.config["puppeteer.connection.host"], + self.config["puppeteer.connection.port"]) + break + except: + self.log.warn(f'No TCP connection open at {self.config["puppeteer.connection.host"]}:{self.config["puppeteer.connection.path"]}, wait for it to become available...') + await asyncio.sleep(10) else: raise RuntimeError("invalid puppeteer connection type") self._reader = r