From 0e650b1a5be5c74a58394d35be1dba3d356a5053 Mon Sep 17 00:00:00 2001 From: matejcik Date: Fri, 30 Jul 2021 14:32:11 +0200 Subject: [PATCH] fix(python): do not set socket to nonblocking for wait_until_ready There's two udp calls in `UdpTransport._ping()`: - socket.sendall(b"PINGPING") -> this will be instanteous, AND it will raise if the receiving side is not listening. - socket.recv() -> this will wait for SOCKET_TIMEOUT seconds, but only in case the sendall() succeeded. This means that receiving side exists and we are now waiting until it's awake enough to respond. In conclusion, we avoid hammering emulator with PINGPINGs with a timeout so short we don't see an answer. This should avoid the problem occasionally seen in CI and described in #1668 --- python/.changelog.d/1668.changed | 1 + python/src/trezorlib/transport/udp.py | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 python/.changelog.d/1668.changed diff --git a/python/.changelog.d/1668.changed b/python/.changelog.d/1668.changed new file mode 100644 index 0000000000..a06c1300cf --- /dev/null +++ b/python/.changelog.d/1668.changed @@ -0,0 +1 @@ +`UdpTransport.wait_until_ready` no longer sets socket to nonblocking diff --git a/python/src/trezorlib/transport/udp.py b/python/src/trezorlib/transport/udp.py index 447ae24986..335e194346 100644 --- a/python/src/trezorlib/transport/udp.py +++ b/python/src/trezorlib/transport/udp.py @@ -91,7 +91,6 @@ class UdpTransport(ProtocolBasedTransport): def wait_until_ready(self, timeout: float = 10) -> None: try: self.open() - self.socket.settimeout(0) start = time.monotonic() while True: if self._ping():