1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

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
This commit is contained in:
matejcik 2021-07-30 14:32:11 +02:00 committed by matejcik
parent 34047cf3ec
commit 0e650b1a5b
2 changed files with 1 additions and 1 deletions

View File

@ -0,0 +1 @@
`UdpTransport.wait_until_ready` no longer sets socket to nonblocking

View File

@ -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():