Skip to content

feat: TCP keepalive timings should be tunables every adapter uses #743

Description

@DavidCozens

Dead-peer detection differs by two orders of magnitude across the TCP adapters,
and the numbers are file-scope constants rather than something an integrator can
size for their deployment.

Where it stands

SolidSyslogPosixTcpStream.c and SolidSyslogWinsockTcpStream.c each declare
their own KEEPALIVE_IDLE_SECONDS = 45, KEEPALIVE_INTERVAL_SECONDS = 10,
KEEPALIVE_PROBE_COUNT = 4 — identical values, written twice — giving an 85 s
worst case. POSIX additionally sets TCP_USER_TIMEOUT to 30 s for the
write-in-flight case, which Windows has no analogue for.

SolidSyslogLwipRawTcpStream.c sets SOF_KEEPALIVE and stops there, so it
inherits lwIP's compile-time defaults: TCP_KEEPIDLE_DEFAULT 7200000 ms,
TCP_KEEPINTVL_DEFAULT 75000 ms, TCP_KEEPCNT_DEFAULT 9 — a first probe after
two hours of silence, and death declared about eleven minutes later.

The lwIP case is the awkward one, because those defaults are stack-wide. An
integrator who wants our stream to behave like the others has to redefine
TCP_KEEPIDLE_DEFAULT in their lwipopts.h, which moves every TCP connection
in their system — their HTTP server, their MQTT client — not just ours. Per-PCB
override is possible in principle (pcb->keep_idle and, under
LWIP_TCP_KEEPALIVE=1, keep_intvl / keep_cnt) but the adapter owns the PCB
and exposes no way to reach it.

Proposal

Compile-time tunables in Core/Interface/SolidSyslogTunablesDefaults.h, in the
established shape of SOLIDSYSLOG_TCP_CONNECT_TIMEOUT_MS, consumed by every TCP
adapter:

  • SOLIDSYSLOG_TCP_KEEPALIVE_IDLE_MS — default 45000
  • SOLIDSYSLOG_TCP_KEEPALIVE_INTERVAL_MS — default 10000
  • SOLIDSYSLOG_TCP_KEEPALIVE_PROBE_COUNT — default 4

Runtime tuning is deliberately not proposed: nobody has needed these per
instance, and a compile-time value is what an embedded integrator sizes once for
the deployment.

Each adapter then applies them in its own idiom — setsockopt on POSIX and
Winsock, the PCB fields on lwIP — so the three agree by construction, and the
duplicated pair of constant blocks collapses to one declaration. Whether
TCP_USER_TIMEOUT also becomes a tunable is worth deciding at the same time; it
has no Windows or lwIP equivalent, so it may stay POSIX-only.

Note the lwIP adapter must not simply set the PCB fields when
LWIP_TCP_KEEPALIVE=0: keep_intvl and keep_cnt do not exist in that build,
so the platform page's existing requirement on that setting becomes load-bearing
rather than advisory.

Until then

The lwIP platform page states the stack defaults and links here, so the gap is
visible to an integrator rather than surprising.

Found during the lwIP documentation triage under #708.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions