5 Commits

Author SHA1 Message Date
darkwolf cf6fbb5f41 use min(interval, 30s) for TCP keepalive period
Adapt keepalive to the configured interval: for short intervals
(e.g. 10s) detection is faster, for long intervals (e.g. 10min)
it caps at 30s as a safety net. Add comments explaining what
problem keepalive solves and its detection time limitation.
2026-03-17 06:40:43 +01:00
darkwolf b6b3fe2678 refactor: use interval as write deadline instead of separate parameter
Simplify the ghost connection fix by reusing the existing interval
duration as the write deadline. This removes the need for a separate
-write_deadline_ms flag while maintaining the same protection against
goroutine leaks from dead connections.
2026-03-12 09:26:38 +01:00
darkwolf ecdfc514d0 Fix ghost connection goroutine leak via write deadline and TCP keepalive
Connections closed by the kernel but not detected by endlessh-go cause
goroutines to run indefinitely, drifting open/closed Prometheus counters.
This happens because conn.Write() succeeds on dead connections when the
kernel buffers data. Kernel 6.12 (Debian 13) is more aggressive at
buffering, making ghosts permanent rather than self-healing.

Changes:
- Add SetWriteDeadline before conn.Write to detect dead connections
- Enable TCP keepalive (30s) on accepted connections for kernel-level
  dead peer detection
- Add defer/recover in send goroutine for robustness
- Add -write_deadline_ms flag (default 30000, 0 to disable)

No new dependencies - uses only Go stdlib net package functions.
2026-03-02 19:14:07 +01:00
Shizun Ge 0d5395b4ee Update copyright to 2026. 2026-01-05 20:07:30 -08:00
Shizun Ge fee1f1a67d re-org files into packages. update copyright. accept multiple ports. 2024-01-18 22:58:35 -08:00