Skip to content

Enable TCP keepalive for upstream and listener sockets - #236

Merged
enteriaza merged 1 commit into
masterfrom
191-bug-tcp-keepalive-upstream-and-listener
Oct 21, 2026
Merged

enteriaza merged 1 commit into
masterfrom
191-bug-tcp-keepalive-upstream-and-listener

Conversation

@enteriaza

Copy link
Copy Markdown
Collaborator

Summary

Fixes #191.

Enable TCP keepalive on outbound upstream NNTP connections and accepted CacheListener client sockets so dead network paths can be detected without relying exclusively on application-level NNTP DATE probes or waiting for application I/O timeouts.

Changes

  • Shared keepalive configuration: Introduce TcpKeepAliveSettings and integrate it with TcpSocketOptions for consistent configuration across both socket paths.
  • Configure upstream connections: Enable TCP keepalive on every upstream TcpClient, including connections created for subsequent reconnects.
  • Configure accepted listener sockets: Apply keepalive to every accepted client socket before normal processing. The listening socket itself is not configured as a substitute for accepted sockets.
  • Independent of DATE: TCP keepalive remains enabled when provider KeepAliveSeconds is zero. Existing application-level DATE behaviour is preserved.
  • Configurable probe timings: Add BackFiller:TcpKeepAlive settings with validated defaults:
    • TimeSeconds: 10 — idle time before the first probe.
    • IntervalSeconds: 5 — interval between probes.
    • RetryCount: 3 — unanswered probes before the connection is considered dead.
  • Handle platform differences: Enabling SO_KEEPALIVE is mandatory. Unsupported per-socket probe-timing options are handled best-effort, retaining the operating system's defaults where necessary.
  • Fail safely: If mandatory keepalive configuration fails, the upstream connection fails or the accepted listener socket is disposed and its admission capacity released.
  • Configuration and documentation: Update option validation, runtime projection, configuration defaults, and docs/configuration.md.

The configured probe timings target a nominal detection window of approximately 25 seconds, subject to operating-system behaviour and scheduling. This is not a hard disconnect-time guarantee.

Validation

  • Focused Pooled NNTP and listener sockets do not enable TCP keepalive #191 tests: 17 passed
  • VectorNNTPD.BackFillerService.Tests (Release x64): 1,333 passed
  • VectorNNTPD.Common.Tests (Release x64): 1,136 passed
  • Release x64 solution build: succeeded
  • dotnet format VectorNNTP.slnx --verify-no-changes: passed
  • tools/Invoke-CodeQlAnalysis.ps1: completed successfully; six pre-existing NntpSessionPool findings remain, with no new findings reported for this change.

Behavioural guarantees

  • Upstream and accepted listener sockets receive TCP keepalive configuration before normal use.
  • TCP keepalive does not depend on application-level DATE probes being enabled.
  • Mandatory keepalive configuration failures do not silently admit an unconfigured socket.
  • Unsupported probe-timing options do not disable SO_KEEPALIVE.
  • Existing NNTP session pooling, listener admission, and application-level keepalive semantics are preserved.

@enteriaza enteriaza self-assigned this Oct 21, 2026
@enteriaza enteriaza added the bug Something isn't working label Oct 21, 2026
@enteriaza
enteriaza merged commit 22b6165 into master Oct 21, 2026
7 checks passed
@enteriaza
enteriaza deleted the 191-bug-tcp-keepalive-upstream-and-listener branch October 21, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pooled NNTP and listener sockets do not enable TCP keepalive

1 participant