feat: add application-level idle keepalive to detect zombie connections#59
Merged
feat: add application-level idle keepalive to detect zombie connections#59
Conversation
Add KeepaliveInterval and KeepaliveCommand fields to Provider, enabling periodic lightweight NNTP probes (DATE/HELP/CAPABILITIES) on idle connections. This detects zombie TCP connections (NAT table expiry, silent firewall drops) before a real request discovers them mid-flight. The probe is injected as a synthetic Request through the normal pipeline so readerLoop maintains FIFO ordering with any pipelined in-flight requests. On probe failure the connection is closed immediately and runConnSlot reconnects on the next request. - KeepaliveInterval: probe interval (0 = disabled, recommended 30s–60s) - KeepaliveCommand: defaults to "DATE" (111); use "HELP" (100) or "CAPABILITIES" (101) for providers that do not support DATE. When SkipPing is true and no explicit command is set, keepalive is disabled automatically since no safe default command is known. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
Summary
KeepaliveIntervalandKeepaliveCommandfields toProviderfor optional application-level idle keepaliveDATE,HELP, orCAPABILITIES) periodically on idle connections to detect zombie TCP connections before a real request discovers themrunConnSlotreconnects automatically on the next requestMotivation
Network paths (NAT tables, firewalls) can silently drop idle TCP connections while the client-side socket still appears open. Without keepalive, zombie connections are only discovered when a real request times out — causing seconds of latency on the next request. This feature detects dead connections proactively during idle periods.
Implementation notes
The probe is injected as a synthetic
*Requestthrough the normal write pipeline soreaderLoopmaintains FIFO ordering with any other in-flight pipelined requests. TheinflightSemslot acquired before the blocking select is owned by the keepalive request;readerLoopreleases it at the normal point (after delivering the response), exactly as for real requests.Configuration
When
SkipPing: trueandKeepaliveCommandis empty, keepalive is disabled automatically (no safe probe command is known for that provider).Test plan
TestKeepalive_KeepsConnectionAlive— server responds correctly to DATE; verifies probe fires and connection remains usable for real requestsTestKeepalive_DeadConnection— server drops connection on DATE; verifiesRun()returns and slot can reconnectmake check(lint + race detector) — all pass🤖 Generated with Claude Code