Skip to content

Commit

Permalink
fix(python): do not set socket to nonblocking for wait_until_ready
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matejcik committed Jul 30, 2021
1 parent e1cc3f1 commit ed9c268
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 1 deletion.
1 change: 1 addition & 0 deletions python/.changelog.d/1668.changed
@@ -0,0 +1 @@
`UdpTransport.wait_until_ready` no longer sets socket to nonblocking
1 change: 0 additions & 1 deletion python/src/trezorlib/transport/udp.py
Expand Up @@ -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():
Expand Down

0 comments on commit ed9c268

Please sign in to comment.