Skip to content

[Bug]: restartConnector waits indefinitely for cloudflared to exit; tunnel stays down ~12 min on a dead HTTP/2 socket #42813

Done

Description

@Amunak

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

Real-world trigger (observed):

  1. Run T3 Code Desktop on Linux with T3 Connect enabled and managed cloudflared running with --protocol http2 (persisted via fix(server): remember T3 Connect HTTP/2 fallback across restarts #28105 / fix(server): T3 Connect remembers when the relay client falls back to HTTP/2 on its own #34167).
  2. Use the host on a flaky mobile connection (roaming cellular hotspot moving through poor-coverage areas, with a Tailscale exit node) so packets/NAT state drop silently and Cloudflare closes the edge side of the HTTP/2 TCP connections without a FIN/RST reaching the host.
  3. Wait for T3 to detect no_connector (Cloudflare has no live connection from the relay client; restarting it) and run CloudManagedEndpointRuntime.restartConnector.

Suggested deterministic repro (untested):

  1. With managed cloudflared connected over --protocol http2, silently blackhole only the existing connections' local ports (e.g., iptables -A OUTPUT -p tcp --dport 7844 --sport <port> -j DROP for each port from ss -tnp | grep cloudflared) so the edge drops the tunnel without sending FIN/RST while still allowing a replacement connector to connect.
  2. Wait for T3 to detect no_connector and trigger restartConnector.
  3. Observe that no new connector starts until the old process exits (~9–13 min), whereas pkill -9 cloudflared recovers in ~5 s.

Expected behavior

When T3 detects that Cloudflare has no live connection and restarts cloudflared, the old cloudflared process should be force-killed (SIGKILL) after a bounded grace timeout so a replacement connector starts promptly and the tunnel recovers within seconds.

Actual behavior

CloudManagedEndpointRuntime.restartConnector calls child.kill() with no timeout and waits indefinitely for cloudflared to exit. When cloudflared is on --protocol http2 with a dead TCP socket stuck in Linux's TCP retransmit backoff (consistent with a half-open socket hitting Linux's default tcp_retries2=15, ~15 min), cloudflared hangs for ~9–13 minutes before exiting.

Because restartConnector holds reconcileSemaphore.withPermits(1), no replacement cloudflared is spawned and applyConfig/reconcile are blocked for the entire hang. Remote clients (e.g., T3 Android) stay stuck on "<host>'s tunnel is offline, retrying attempt 1, 2, 3, 4...".

Observed 3 times in one morning (2026-11-25) while roaming through poor cellular coverage on the same host:

  • 09:23:53Z → 09:33:20Z (~9.5 min hang before Relay client stopped)
  • 10:25:28Z → 10:37:46Z (CloudManagedEndpointRuntime.restartConnector span durationMs: 737989.5, i.e., 12 min 18 s)
  • ~11:13Z → 11:26Z (sockets stuck in rto:120000, backoff:8..10, last ACK 8–13 min ago)

As soon as the old cloudflared finally exits, the new cloudflared registers all 4 connections within ~5 seconds.

Code-level cause:

  • restartConnector in apps/server/src/cloud/ManagedEndpointRuntime.ts:909-924 calls active.child.kill() with no options while holding reconcileSemaphore.withPermits(1).
  • The readiness watcher in ManagedEndpointRuntime.ts:589 (Relay client has no tunnel connection; restarting it) also calls bare child.kill().
  • The spawn call (ManagedEndpointRuntime.ts:783-807) also sets no forceKillAfter, so scope-close cleanup (stopActive, used by switchToHttp2 and reconcile) can hang the same way.
  • Effect's ChildProcess.kill() defaults forceKillAfter to undefined, sending SIGTERM and waiting indefinitely without escalating to SIGKILL. Passing a bounded forceKillAfter on both kill() and the spawn options (similar to how RelayClientLedger in fix(server): stop the relay client a crashed server left running #36465 already escalates to SIGKILL) would prevent unbounded hangs.

Related issues/PRs (distinct from this bug):

Impact

Major degradation or frequent failure

Version or commit

0.1.12-nightly.20261125.5222 (also observed on 0.1.12-nightly.20261125.5230)

Environment

Fedora Linux x86_64, T3 Code Nightly AppImage, managed cloudflared 2026.10.4 (--protocol http2), Tailscale exit node over roaming cellular hotspot

Logs or stack traces

# server.trace.ndjson (abridged; restartConnector span lasted 737,989 ms = 12m 18s)
name: "CloudManagedEndpointRuntime.restartConnector"
durationMs: 737989.503073
event: "Cloudflare has no live connection from the relay client; restarting it" (pid: 757441)

# relay-client.ndjson (abridged; 30s after restartConnector started, then silent for ~12 min)
2026-11-25T10:25:58Z ERR failed to serve incoming request error="Error shutting down control stream: context deadline exceeded"
2026-11-25T10:25:58Z ERR failed to serve incoming request error="Error shutting down control stream: context canceled"
# ... ~12 minutes later ...
2026-11-25T10:37:46.635Z Relay client stopped
2026-11-25T10:37:46.635Z Relay client exited; restarting
2026-11-25T10:37:46.639Z Relay client process started; waiting for tunnel connection
2026-11-25T10:37:49.472Z INF Registered tunnel connection connIndex=0 ... protocol=http2
2026-11-25T10:37:52.142Z INF Registered tunnel connection connIndex=3 ... protocol=http2

# ss -tinp sample while cloudflared pid 757441 was hung (~10:36Z)
ESTAB 0 24293 <tailnet-ip>:<port> 198.41.192.7:7844 users:(("cloudflared",pid=757441,fd=8))
  cubic rto:120000 backoff:14 mss:1228 pmtu:1280 cwnd:1 lastsnd:67686 lastrcv:977030 lastack:963624 unacked:1 retrans:1/26 lost:1 notsent:23889

Workaround

Run pkill -9 cloudflared on the host so T3 immediately spawns a fresh connector, or pair directly over LAN/Tailscale without T3 Connect.

Activity

  1. added
    bug
    needs-triage
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions