File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Skip stale protocol v1 responses on probing.
Original file line number Diff line number Diff line change 2929from .log import DUMP_BYTES
3030from .thp import pairing
3131from .tools import enter_context
32+ from .transport import Timeout
3233
3334if t .TYPE_CHECKING :
3435 from .mapping import ProtobufMapping
@@ -350,6 +351,12 @@ def probe(
350351 transport : Transport , * , mapping : ProtobufMapping = mapping .DEFAULT_MAPPING
351352) -> bool :
352353 """Probe the transport to see if it supports protocol v1."""
354+ while True :
355+ try :
356+ resp = read (transport , _ignore_bad_magic = True , timeout = 0.1 )
357+ LOG .debug ("stale response: %s" , resp )
358+ except Timeout :
359+ break
353360 cancel_msg = messages .Cancel ()
354361 cancel_msg_type , cancel_msg_bytes = mapping .encode (cancel_msg )
355362 write (transport , cancel_msg_type , cancel_msg_bytes )
Original file line number Diff line number Diff line change 1717import pytest
1818
1919from trezorlib import messages , models
20+ from trezorlib .client import get_client
2021from trezorlib .debuglink import DebugSession as Session
2122from trezorlib .debuglink import TrezorTestContext as Client
2223
@@ -72,3 +73,15 @@ def test_not_initialized(session: Session):
7273 messages .FailureType .InvalidSession ,
7374 )
7475 assert resp .code == expected [session .test_ctx .is_thp ()]
76+
77+
78+ def test_desync (client : Client ):
79+ with client .get_session (passphrase = None ) as session :
80+ resp = session .call_raw (messages .Ping (message = "test" , button_protection = True ))
81+ messages .ButtonRequest .ensure_isinstance (resp )
82+ session .write (messages .ButtonAck ())
83+ session .debug .press_no ()
84+ # don't read the response - simulating host disconnection
85+
86+ # Creating a new client not fail (https://github.com/trezor/trezor-firmware/issues/6859)
87+ get_client (client .app , client .transport ).ping ("reconnect" )
You can’t perform that action at this time.
0 commit comments