Skip to content

Commit d028d42

Browse files
committed
fixup! fix(python): skip stale protocol v1 responses
1 parent 58636d4 commit d028d42

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

python/src/trezorlib/protocol_v1.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ def _read(self, session: SessionV1, timeout: float | None = None) -> MessageType
348348

349349
@enter_context
350350
def probe(
351-
transport: Transport, *, mapping: ProtobufMapping = mapping.DEFAULT_MAPPING
351+
transport: Transport,
352+
*,
353+
mapping: ProtobufMapping = mapping.DEFAULT_MAPPING,
354+
retries: int = 10,
352355
) -> bool:
353356
"""Probe the transport to see if it supports protocol v1."""
354-
while True:
357+
for _ in range(retries):
355358
try:
359+
# skip stale responses (to prevent the device from blocking during sending)
356360
resp = read(transport, _ignore_bad_magic=True, timeout=0.1)
357361
LOG.debug("stale response: %s", resp)
358362
except Timeout:

0 commit comments

Comments
 (0)