From c2e1b00d65295e59ece4b4975a19a57fc1ef60b3 Mon Sep 17 00:00:00 2001 From: tkeairns Date: Mon, 30 Nov 2026 20:14:55 -0800 Subject: [PATCH] doip: a tester that stops reading holds the others up 1 s, not 10 SO_SNDTIMEO needs CONFIG_NET_CONTEXT_SNDTIMEO: without it the option is refused and a blocked send waits CONFIG_NET_SOCKET_MAX_SEND_WAIT, 10 s, with every other tester unanswered meanwhile. --- snippets/ethernet/ethernet.conf | 5 +++++ testing/suites/doip/test_entity.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/snippets/ethernet/ethernet.conf b/snippets/ethernet/ethernet.conf index d31df76..1ab1375 100644 --- a/snippets/ethernet/ethernet.conf +++ b/snippets/ethernet/ethernet.conf @@ -21,6 +21,11 @@ CONFIG_NET_MGMT_EVENT=y # boot up to 30 s waiting for a link. CONFIG_NET_CONFIG_SETTINGS=n +# SO_SNDTIMEO, DoIP's bound on a send to a tester that stopped reading. Without +# it the option is refused and a blocked send waits 10 s +# (CONFIG_NET_SOCKET_MAX_SEND_WAIT). +CONFIG_NET_CONTEXT_SNDTIMEO=y + CONFIG_NET_MAX_CONTEXTS=12 CONFIG_NET_MAX_CONN=12 CONFIG_ZVFS_OPEN_MAX=16 diff --git a/testing/suites/doip/test_entity.py b/testing/suites/doip/test_entity.py index 6ac6209..d18083a 100644 --- a/testing/suites/doip/test_entity.py +++ b/testing/suites/doip/test_entity.py @@ -140,6 +140,29 @@ def test_a_third_tester_is_refused(host): assert c.closed() +def test_a_tester_that_stops_reading_is_closed_within_a_second(host): + with Raw(host) as stalled, Raw(host) as other: + assert stalled.activate(0x0E80) == 0x10 + assert other.activate(0x0E81) == 0x10 + # More answers than its receive buffer and the entity's send window hold, none read. + stalled.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2048) + stalled.sock.settimeout(0.2) + try: + for _ in range(600): + stalled.send(doip.DIAGNOSTIC, struct.pack("!HH", 0x0E80, ECU) + b"\x22\xf1\x90") + except TimeoutError: + pass + # The entity waits on it 1 s at most, once; the other tester is answered again after. + worst, end = 0.0, time.monotonic() + frames.bound(3.0) + while time.monotonic() < end: + started = time.monotonic() + assert other.request(b"\x3e\x00", source=0x0E81) == b"\x7e\x00" + worst = max(worst, time.monotonic() - started) + assert worst < frames.bound(1.0) + 2 * SLACK_S, worst + # Its socket is the entity's to give again: one open, the other tester's. + assert doip.udp(host, ENTITY_STATUS)[0][3][2] == 1 + + def test_initial_inactivity(host): with Raw(host) as a: started = time.monotonic()