Better node disconnect handling

This commit is contained in:
Andrew Ferrazzutti 2022-04-11 04:48:48 -04:00
parent 95d08e5aeb
commit 3bf49123f5

View File

@ -144,9 +144,9 @@ class RPCClient:
self._reader = r
self._writer = w
self._read_task = self.loop.create_task(self._try_read_loop())
await self._raw_request("register", peer_id=self.config["appservice.address"])
self._is_connected.set()
self._is_disconnected.clear()
await self.request("register", peer_id=self.config["appservice.address"])
async def disconnect(self) -> None:
async with self._connection_lock:
@ -258,9 +258,11 @@ class RPCClient:
try:
await self._read_loop()
except asyncio.CancelledError:
pass
return
except:
self.log.exception("Fatal error in read loop")
self.log.debug("Reader disconnected")
self._on_disconnect()
async def _read_loop(self) -> None:
while self._reader is not None and not self._reader.at_eof():
@ -275,9 +277,6 @@ class RPCClient:
except asyncio.LimitOverrunError as e:
self.log.warning(f"Buffer overrun: {e}")
line += await self._reader.read(self._reader._limit)
except ConnectionResetError:
if self._reader is not None:
raise
except asyncio.CancelledError:
raise
if not line:
@ -293,8 +292,6 @@ class RPCClient:
raise
except:
self.log.exception("Failed to handle incoming request %s", line_str)
self.log.debug("Reader disconnected")
self._on_disconnect()
async def _raw_request(self, command: str, is_secret: bool = False, **data: JSON) -> asyncio.Future[JSON]:
req_id = self._next_req_id