Repository navigation
various restart/devbox fixes - #288
Conversation
|
@daniel-de-vera comments addressed |
sorry there was some cross-fire, one thing pending... |
|
@scott-cotton, I'm done with the code review, will do some testing now. |
Also distinguish restart from not-ok more correctly in tp_monitor
a2fdad9 to
6a2e592
Compare
now all comments addressed and re-tested. please note regarding
I didn't do that because I want the state to be top-down readable, and the timeouts are a function of restarting so separating them seems less readable to me. However, following your advice would have fixed another hole. So, I refactored for additional clarity -- new sub functions and distinguish need to restart from checks passed explicitly. |
| } | ||
|
|
||
| func (mon *tpMonitor) checkTunnelProxyAccess(ctx context.Context) bool { | ||
| func (mon *tpMonitor) checkTunnelProxyAccess(ctx context.Context) (success bool, restarted bool) { |
There was a problem hiding this comment.
Nit: I would remove the named return values (as we are not using them).
There was a problem hiding this comment.
I like the documentation effect upon reading the signature :)
daniel-de-vera
left a comment
There was a problem hiding this comment.
LGTM, just left one minor comment about named return values.
Fix: Devbox Session Management and Service Recovery Improvements
Overview
This branch includes several critical fixes and improvements to devbox session management and service recovery:
sessionReleasedfield - no longer tracked since renewals auto-claimIt also adds hidden gops-root-addr and gops-non-root-addr flags to signadot local connect to facilitate getting gops stacks and info on locald root manager and locald sandboxmanager.
Problem 1: Stale HTTP Connections After Sleep
Issue
After a sleep period during
signadot local connect, the devbox session manager would encounter "connection reset by peer" errors when trying to renew the session. This was caused by reusing a cached HTTP client with stale TCP connections.Root Cause
The
SessionManagerwas storing a singleapiClientinstance and reusing it across all renewal requests. After sleep periods, the underlying TCP connections would be closed by the server, but the client would attempt to reuse them.Solution
Changed to create a fresh API client for each renewal request. This ensures each request gets a new HTTP client/transport, avoiding stale connection errors.
Key Changes:
apiClientfield fromSessionManagerstructrenewSession()to create a new API client for each callreleaseSession()to create a new API client for each callProblem 2: Shutdown on Session Release
Issue
When a devbox session was released server-side, the session manager would trigger a shutdown of the entire sandbox manager, requiring manual reconnection.
Root Cause
The code was designed to shut down when a session was released, but the server-side API semantics changed: renewals now automatically claim a new session if the current one is released.
Solution
Removed the shutdown-on-release mechanism entirely. Renewals now automatically claim a new session if released, so there's no need to shut down.
Key Changes:
shutdownChparameter fromNewSessionManager()triggerShutdown()methodhandleSessionChange()to gracefully handle session ID changes without shutdownProblem 3: Session Released State Tracking
Issue
The code tracked a
sessionReleasedboolean state, but since renewals automatically claim new sessions when released, this state was meaningless and always false.Root Cause
The
sessionReleasedfield was based on the assumption that renewals would fail when a session was released. However, renewals now succeed and claim a new session, so the released state is never observable.Solution
Removed
sessionReleasedfield and all references to it throughout the codebase.Key Changes:
sessionReleasedfield fromSessionManagerstructWasSessionReleased()methodGetStatus()to return 5 values instead of 6 (removedsessionReleased)sessionReleasedfromDevboxSessionStatusproto messagesessionReleasedcheckssandbox_manager.goProblem 4: Static Session ID in Sandbox Watcher
Issue
The sandbox watcher used a static
devboxSessionIDthat was set at initialization. If the session ID changed during runtime (e.g., after a renewal claims a new session), the watcher would continue watching with the old session ID, missing sandboxes associated with the new session.Root Cause
The watcher stored the session ID as a string field set once during initialization. Watch streams are long-lived, so even if the session ID changed, the watcher wouldn't pick up the change until the stream errored out (which could take a long time).
Solution
Changed the watcher to use a function that dynamically retrieves the current session ID. Added periodic checks during the watch stream to detect session ID changes and proactively restart the stream.
Key Changes:
devboxSessionID stringfield togetDevboxSessionID func() stringwatchSandboxes()to callgetDevboxSessionID()for each new watch streamreadStream()(every 5 seconds)Problem 5: Restart Loop After WiFi Reconnection
Issue
After turning WiFi off and back on, the tunnel proxy monitor would restart services repeatedly, causing excessive pfctl operations and log spam.
Root Cause
The
agent-metricshealth check didn't respect the 30-second startup grace period. When WiFi reconnected, the check would fail and immediately trigger a restart, which would fail again on the next check (1 second later), creating a restart loop.Solution
Made the
agent-metricscheck respect the same grace period logic as other health checks. During the startup phase (first 30 seconds), failed checks wait instead of immediately restarting.Key Changes:
agent-metricscheck to useshouldRestartDueToUnhealthy()helpermaxStartingTimegrace periodTechnical Details
Session Manager Changes
Before:
After:
Sandbox Watcher Changes
Before:
After:
Tunnel Proxy Monitor Changes
Before:
After:
Benefits
sessionReleasedfieldTesting Considerations