diff --git a/selfdrive/athena/athenad.py b/selfdrive/athena/athenad.py index 833bf841f5..ca3a1bafbb 100755 --- a/selfdrive/athena/athenad.py +++ b/selfdrive/athena/athenad.py @@ -746,6 +746,9 @@ def ws_manage(ws: WebSocket, end_event: threading.Event) -> None: onroad_prev = onroad if sock is not None: + # While not sending data, onroad, we can expect to time out in 7 + (7 * 2) = 21s + # offroad, we can expect to time out in 30 + (10 * 3) = 60s + # FIXME: TCP_USER_TIMEOUT is effectively 2x for some reason (32s), so it's mostly unused sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_USER_TIMEOUT, 16000 if onroad else 0) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 7 if onroad else 30) sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 7 if onroad else 10) diff --git a/selfdrive/athena/tests/test_athenad_ping.py b/selfdrive/athena/tests/test_athenad_ping.py index 49bd5f1142..7f32f60cb4 100755 --- a/selfdrive/athena/tests/test_athenad_ping.py +++ b/selfdrive/athena/tests/test_athenad_ping.py @@ -12,6 +12,8 @@ from openpilot.selfdrive.athena import athenad from openpilot.selfdrive.manager.helpers import write_onroad_params from openpilot.system.hardware import TICI +TIMEOUT_TOLERANCE = 20 # seconds + def wifi_radio(on: bool) -> None: if not TICI: @@ -63,7 +65,7 @@ class TestAthenadPing(unittest.TestCase): mock_create_connection.assert_called_once() mock_create_connection.reset_mock() - # check normal behaviour + # check normal behaviour, server pings on connection with self.subTest("Wi-Fi: receives ping"), Timeout(70, "no ping received"): while not self._received_ping(): time.sleep(0.1) @@ -92,12 +94,12 @@ class TestAthenadPing(unittest.TestCase): @unittest.skipIf(not TICI, "only run on desk") def test_offroad(self) -> None: write_onroad_params(False, self.params) - self.assertTimeout(100) # expect approx 90s + self.assertTimeout(60 + TIMEOUT_TOLERANCE) # based using TCP keepalive settings @unittest.skipIf(not TICI, "only run on desk") def test_onroad(self) -> None: write_onroad_params(True, self.params) - self.assertTimeout(30) # expect 20-30s + self.assertTimeout(21 + TIMEOUT_TOLERANCE) if __name__ == "__main__":