fix(dlt-receive): set SO_RCVTIMEO and SO_KEEPALIVE to enable -r reconnect on half-open TCP#845
Open
aki1770-del wants to merge 1 commit into
Open
Conversation
…nect on half-open TCP Fixes COVESA#817. With half-open TCP (VM/container restart, network partition), recv() blocks forever and the -r reconnect interval is never consulted. Fix: add recv_timeout_sec field to DltClient (default 0 = no change). In dlt_client_connect(): if recv_timeout_sec > 0, set SO_RCVTIMEO; always set SO_KEEPALIVE + TCP_KEEPIDLE/INTVL/CNT where available. In dlt-receive.c: wire recv_timeout_sec = rvalue/1000 (min 5s) before reconnect loop when -r is active. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Akihiko Komada <aki1770@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(dlt-receive): set SO_RCVTIMEO and SO_KEEPALIVE in dlt_client_connect to enable -r reconnect on half-open TCP
Fixes #817.
Problem
dlt-receive -r <interval>is supposed to reconnect automatically when theDLT daemon becomes unavailable. This works correctly for clean disconnects
(RST/FIN received):
dlt_receiver_receive()returns ≤0,dlt_client_main_loopexits, and the reconnect loop fires after the specified interval.
However, when the network path fails silently — half-open TCP, common in
VM/container restarts and network partitions — the kernel socket stays in
ESTABLISHEDstate.dlt_receiver_receive()callsrecv()which blocksforever. The reconnect interval is never consulted.
Fix
Three files changed:
include/dlt/dlt_client.h: Addrecv_timeout_secfield toDltClientstruct (0 = no timeout, backwards-compatible default).
src/lib/dlt_client.c— indlt_client_connect(), after blocking modeis restored on a successful TCP connect:
client->recv_timeout_sec > 0: callsetsockopt(SO_RCVTIMEO)with theconfigured timeout. When
recv()times out it returns -1/EAGAIN, whichdlt_receiver_receive()maps to a ≤0 return, causingdlt_client_main_loopto exit and the reconnect loop to fire.
SO_KEEPALIVE(+TCP_KEEPIDLE/TCP_KEEPINTVL/TCP_KEEPCNTwhere available) as a second line of defence.
src/console/dlt-receive.c— before the reconnect loop: when-risactive, set
dltclient.recv_timeout_sec = rvalue / 1000(minimum 5 s) sothe socket timeout matches the reconnect interval.
Behaviour
-rnot set)recv()blocks foreverrecv()blocks forever (no change — timeout = 0)-r 5000= 5 s)recv()blocks forever,-rignoredrecv()times out after 5 s, reconnect firesAI-assisted — authored with Claude, reviewed by Komada.