[thread-cert] handle BrokenPipeError on resetting node in simulator (#13495)

When a simulated node restarts (e.g. during `factoryreset`), the
child process re-executes itself via `execvp`, disconnecting its
UNIX domain socket connection to the virtual-time simulator.

If `VirtualTime._send_message()` attempts to send an event before the
socket disconnection event has been processed by `selectors`,
`sock.send()` raises `BrokenPipeError` or `ConnectionResetError`,
even though the node is marked as temporarily offline in
`_maybeoff_ports` (via `maybeoff=True`).

This commit catches `BrokenPipeError` and `ConnectionResetError` in
`VirtualTime._send_message()`, verifying that the destination port is
present in `_maybeoff_ports` and skipping delivery cleanly.
This commit is contained in:
Jonathan Hui
2026-08-13 10:52:07 -07:00
committed by GitHub
parent c9d3215b0f
commit 522a665187
+6 -1
View File
@@ -511,7 +511,12 @@ class VirtualTime(BaseSimulator):
else:
sock = self.devices[port].get('sock', None)
if sock:
sent = sock.send(message)
try:
sent = sock.send(message)
except (BrokenPipeError, ConnectionResetError):
assert port in self._maybeoff_ports, f'The node {port} is unexpectedly off'
dbg_print('skip sending message to off node', port)
return
else:
assert port in self._maybeoff_ports, f'The node {port} is unexpectedly off'
dbg_print('skip sending message to off node', port)