From ede3c95c3f13513df5dac942da77517a0a6ffeec Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 16 Sep 2024 16:25:48 +0200 Subject: [PATCH] fix(python): opportunistically catch a debuglink desync In certain cases a DebugLinkState response can get stalled and debuglink will not read it -- i.e., a situation analogous to wirelink de-sync. There doesn't seem to be a good way to force-sync debuglink the same way wirelink does it, but we can detect a wrong response to a DebugLinkGetState and skip it. --- python/src/trezorlib/debuglink.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index 994978309f..1aa4d99098 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -521,6 +521,8 @@ class DebugLink: self, wait_type: DebugWaitType = DebugWaitType.CURRENT_LAYOUT ) -> messages.DebugLinkState: result = self._call(messages.DebugLinkGetState(wait_layout=wait_type)) + while not isinstance(result, (messages.Failure, messages.DebugLinkState)): + result = self._read() if isinstance(result, messages.Failure): raise TrezorFailure(result) return result