Skip to content

v0.31.1

Choose a tag to compare

@github-actions github-actions released this 16 Dec 04:24
· 138 commits to main since this release
00328c1
fix: detect network disconnections in bastion tunnel (#4)

* fix: properly handle websocket timeouts and connection closures

The bastion tunnel command was not properly detecting when websocket connections
timed out or closed, causing the command to hang indefinitely even though the
connection was dead. This left users thinking the connection was still active.

**Root Cause:**
- Error threshold logic (displaying errors only after 3 occurrences) prevented
  immediate connection closure
- No mechanism to detect when both forwarding goroutines had completed
- Select loop waited indefinitely for more errors even after goroutines exited

**Changes:**
- Add doneChan to signal when each goroutine completes
- Track number of completed goroutines (0/2, 1/2, 2/2)
- Return immediately on any error instead of using error threshold
- Return when both goroutines complete (normal closure)
- Improve error messages to clearly indicate connection closure

**Behavior:**
- Websocket timeout -> immediate connection closure with error message
- Normal connection close -> silent cleanup and return
- Fatal errors -> immediate closure with descriptive message
- Both goroutines done -> clean return

This ensures the command properly exits when connections are no longer active.

* fix: detect network disconnections with WebSocket ping/pong

When network connectivity is lost (e.g., WiFi disabled), the bastion tunnel
command would hang indefinitely without detecting the broken connection. This
left users unaware that their connection was dead.

**Root Cause:**
- No ping/pong mechanism to detect dead connections
- No read/write deadlines set on WebSocket
- Blocking reads would wait forever even when network is gone

**Solution:**
Add comprehensive connection health monitoring:

1. **Ping/Pong Keepalive:**
   - Send WebSocket ping every 54 seconds
   - Expect pong response within 60 seconds
   - Fail fast if pong not received (network dead)

2. **Read Deadlines:**
   - Set 60 second read deadline on WebSocket
   - Extend deadline on each successful read
   - Extend deadline on each pong received
   - Timeout triggers connection closure with clear error

3. **Timeout Detection:**
   - Detect net.Error timeout specifically
   - Report as "connection timeout - network may be disconnected"
   - Immediate command exit with user-visible error

**Behavior:**
Before: Network disconnect → command hangs forever ❌
After: Network disconnect → detected within 60s → command exits ✓

**Testing:**
- Disconnect WiFi → Command exits with timeout error within 60s
- Ping failure → Command exits immediately with health check error
- Normal operation → Pings extend deadline, no interruption

* fix: detect network disconnections in bastion tunnel

- Add health check goroutine that monitors Azure Bastion connectivity every 5 seconds
- Health check runs even when tunnel is idle (no active connections)
- Fails after 2 consecutive failures (~11 seconds detection time)
- Exit cleanly with single error message and non-zero exit code
- Add SilenceUsage to prevent help menu on errors