From 81453685b72788ec82a7e8998388240edca72189 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 00000000000..a06c1300cfd --- /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 447ae24986b..335e194346c 100644 --- a/python/src/trezorlib/transport/udp.py +++ b/python/src/trezorlib/transport/udp.py @@ -91,7 +91,6 @@ def find_by_path(cls, path: str, prefix_search: bool = False) -> "UdpTransport": def wait_until_ready(self, timeout: float = 10) -> None: try: self.open() - self.socket.settimeout(0) start = time.monotonic() while True: if self._ping():