Skip to content

Harden search-relay ↔ search-proxy keepalive against idle disconnects - #16

Open
znsoftm wants to merge 1 commit into
mainfrom
cursor/tunnel-keepalive-c622
Open

znsoftm wants to merge 1 commit into
mainfrom
cursor/tunnel-keepalive-c622

Conversation

@znsoftm

@znsoftm znsoftm commented Sep 14, 2026

Copy link
Copy Markdown
Member

Idle public tunnels were dying after hours with {"ok":false,"error":"search backend offline","code":"offline"} because NAT / a 90s ReadDeadline closed the link even though the relay already reconnects.

Both ends now keep the TCP path warm and fail dead sessions faster:

  • App-level ping every 12s; missing pong within 45s closes the session and the relay reconnects
  • 60s read deadline, refreshed on every frame including ping/pong
  • TCP keepalive 15s on dial (KeepAliveConfig + SetKeepAlivePeriod) and on the accepted proxy conn
  • Relay reconnect backoff 500ms → 10s, reset after a healthy session
  • Proxy emits pings (not only answers), so the idle public path stays warm
  • Reconnect / disconnect logs include the reason (missing pong, read idle timeout, etc.)

Shared helpers live in internal/tunnel with tests for deadline refresh, pong timeout, backoff, and proxy ping emit/answer.

Open in Web Open in Cursor 

Ping both sides every 12s, fail a missing pong in 45s, refresh a 60s
read deadline on every frame, tighten TCP keepalive to 15s, and reconnect
the relay from 500ms up to 10s with an explicit drop reason.

Co-authored-by: Daniel <znsoft@163.com>
@znsoftm
znsoftm marked this pull request as ready for review September 14, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants