From e493a5290b6c0c7467c0b29f9cff6e30504d504f Mon Sep 17 00:00:00 2001 From: WorldObservationLog Date: Wed, 22 May 2024 00:01:05 +0800 Subject: [PATCH] fix: retry when raise ConnectionRefusedError --- src/decrypt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/decrypt.py b/src/decrypt.py index 04b9aee..9143740 100644 --- a/src/decrypt.py +++ b/src/decrypt.py @@ -18,7 +18,12 @@ retry_count = {} async def decrypt(info: SongInfo, keys: list[str], manifest: Datum, device: Device) -> bytes: async with device.decryptLock: logger.info(f"Decrypting song: {manifest.attributes.artistName} - {manifest.attributes.name}") - reader, writer = await asyncio.open_connection(device.host, device.fridaPort) + try: + reader, writer = await asyncio.open_connection(device.host, device.fridaPort) + except ConnectionRefusedError: + logger.warning(f"Failed to connect to device {device.device.serial}, re-injecting") + device.restart_inject_frida() + raise RetryableDecryptException decrypted = bytes() last_index = 255 for sample in info.samples: