From ef905463248d5a73de1b569872db386463f664b0 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 cd445049a6..4e4c5bf73d 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