You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(tunnel): add network-wait mode for transient DNS outages
The watchdog used to burn all 10 restart attempts during any network
outage longer than ~6 minutes and then permanently give up, leaving the
tunnel dead even after connectivity returned (common overnight: Wi-Fi
sleep, DHCP renewal, ISP DNS blip, EAI_NONAME on macOS).
Now DNS / connectivity errors route to a new network-wait state that
mirrors the existing auth-wait pattern: probes the DevTunnel host via
DNS every 60s and resumes automatically when reachable. Network errors
no longer consume restart attempts, and the 10-attempt ceiling
transitions into network-wait instead of a terminal giveup.
- src/tunnel/index.js: NETWORK_ERROR_PATTERNS, isNetworkError,
isNetworkReachable, startNetworkWait/stopNetworkWait; new
'network-lost' / 'network-restored' events
- test/tunnel/watchdog.test.js: unit tests for classifiers + events
- docs/architecture.md, docs/troubleshooting.md: describe new behavior
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/architecture.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -117,10 +117,11 @@ Manages Azure DevTunnel lifecycle: login, create, host, cleanup. Includes a **wa
117
117
-**Health check** — every 30 seconds, runs `devtunnel show` and parses the host connection count.
118
118
-**Zombie detection** — if host connections drop to 0 for two consecutive checks (60s grace), the stale process is killed and a restart is initiated.
119
119
-**Crash detection** — an `exit` handler on the child process triggers immediate restart if the process dies.
120
-
-**Auto-restart** — exponential backoff (1s → 2s → 5s → 10s → 15s → 30s), up to 10 attempts before giving up.
120
+
-**Auto-restart** — exponential backoff (1s → 2s → 5s → 10s → 15s → 30s), up to 10 attempts before transitioning to network-wait.
121
121
-**Auth-wait system** — detects auth token expiry (Microsoft limitation), enters an auth-wait mode, polls for re-authentication via device code flow, and auto-reconnects once a fresh token is obtained.
122
+
-**Network-wait system** — detects DNS / connectivity errors (e.g. `ENOTFOUND`, `EAI_AGAIN`, `nodename nor servname`), enters a network-wait mode, probes the DevTunnel host via DNS every 60 seconds, and auto-reconnects once the network is reachable again. Network errors do not consume restart attempts, so transient outages (Wi-Fi sleep, DHCP renewal, ISP DNS blips) no longer cause a permanent giveup.
122
123
-**Token lifetime monitoring** — tracks the remaining lifetime of the DevTunnel auth token and emits warnings when less than 1 hour remains, giving the frontend time to prompt the user.
123
-
-**Event emitter** — exports `tunnelEvents` (EventEmitter) with events: `connected`, `disconnected`, `reconnecting`, `failed`. The server subscribes for logging.
124
+
-**Event emitter** — exports `tunnelEvents` (EventEmitter) with events: `connected`, `disconnected`, `reconnecting`, `network-lost`, `network-restored`, `failed`. The server subscribes for logging.
124
125
125
126
Also exports `getLoginInfo()` (returns current auth provider and token expiry) and `parseLoginInfo()` (parses raw `devtunnel` CLI output into structured login metadata).
Copy file name to clipboardExpand all lines: docs/troubleshooting.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,6 +79,12 @@ devtunnel user login
79
79
!!! warning
80
80
If a persisted tunnel stops working after ~30 days, delete `~/.termbeam/tunnel.json` and restart TermBeam to create a fresh tunnel.
81
81
82
+
### Tunnel died overnight / after sleep
83
+
84
+
If TermBeam is running as a long-lived service (`termbeam service`) and the tunnel stops working after a network interruption (laptop sleep, Wi-Fi drop, DHCP renewal, ISP DNS blip, etc.), the watchdog automatically enters a **network-wait** state once transient DNS / connectivity errors are detected. It probes the DevTunnel host every 60 seconds and reconnects as soon as the network is reachable again — no manual restart required.
85
+
86
+
You'll see `[WARN] Tunnel paused — waiting for network connectivity` in the logs followed by `[INFO] Network connectivity restored — resuming tunnel` when it recovers. If the logs instead show repeated `Tunnel restart returned no URL` with no final giveup, the watchdog is still cycling through its 10 restart attempts; wait a few minutes for it to settle into network-wait.
0 commit comments