diff --git a/python/src/trezorlib/transport/protocol.py b/python/src/trezorlib/transport/protocol.py index 4a2c129ec6..42f51a4b08 100644 --- a/python/src/trezorlib/transport/protocol.py +++ b/python/src/trezorlib/transport/protocol.py @@ -21,7 +21,7 @@ import struct from typing_extensions import Protocol as StructuralType -from . import MessagePayload, Transport +from . import MessagePayload, Timeout, Transport REPLEN = 64 @@ -82,6 +82,14 @@ class Protocol: def begin_session(self) -> None: if self.session_counter == 0: self.handle.open() + try: + # Drop queued responses to old requests + while True: + msg = self.handle.read_chunk(timeout=0.1) + LOG.warning("ignored: %s", msg) + except Timeout: + pass + self.session_counter += 1 def end_session(self) -> None: diff --git a/python/src/trezorlib/transport/udp.py b/python/src/trezorlib/transport/udp.py index a4652b6fbf..2a8d3e620f 100644 --- a/python/src/trezorlib/transport/udp.py +++ b/python/src/trezorlib/transport/udp.py @@ -28,7 +28,7 @@ from .protocol import ProtocolBasedTransport, ProtocolV1 if TYPE_CHECKING: from ..models import TrezorModel -SOCKET_TIMEOUT = 10 +SOCKET_TIMEOUT = 0.1 LOG = logging.getLogger(__name__)