Skip to content

Fix SSH tunnel not restarted on unexpected process exit#133

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ssh-tunnel-restart-issue
Closed

Fix SSH tunnel not restarted on unexpected process exit#133
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ssh-tunnel-restart-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

When the SSH tunnel process crashed, SshTunnelService only logged a warning — it never cleaned up _process/_lastSpec, never fired an event, and never attempted a restart. The gateway client's reconnect loop would spin indefinitely against a dead localhost port.

Changes

SshTunnelService

  • Adds TunnelExited event, raised only on unexpected exits (not on intentional Stop())
  • On unexpected exit: nulls _process and _lastSpec (so the next EnsureStarted starts fresh), disposes the dead process object (fixes a resource leak), then fires TunnelExited

App.xaml.cs

  • Subscribes to TunnelExited at service creation
  • OnSshTunnelExited retries EnsureSshTunnelConfigured() with bounded backoff (1 s → 2 s → 5 s → 10 s → 30 s); aborts early if the app is exiting or SSH tunnel is disabled. The gateway client's existing reconnect loop recovers automatically once the tunnel port is live again.
process.Exited += (_, _) =>
{
    if (_stopping) { /* intentional shutdown */ }
    else
    {
        _process = null;
        _lastSpec = null;
        try { process.Dispose(); } catch (Exception ex) { _logger.Warn(...); }
        TunnelExited?.Invoke(this, EventArgs.Empty);
    }
};

- Add TunnelExited event to SshTunnelService
- Null _process/_lastSpec and dispose the process on unexpected exit, then fire TunnelExited
- Subscribe to TunnelExited in App.xaml.cs with bounded retry backoff (1s/2s/5s/10s/30s)

Agent-Logs-Url: https://github.com/openclaw/openclaw-windows-node/sessions/a69d5952-fc73-46fe-9d2b-e5596c75ea4c

Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SSH tunnel not restarted on unexpected exit Fix SSH tunnel not restarted on unexpected process exit Apr 1, 2026
Copilot AI requested a review from shanselman April 1, 2026 17:28
@shanselman
Copy link
Copy Markdown
Collaborator

Superseded by PR #141 (merged) — SSH tunnel restart fix.

@shanselman shanselman closed this Apr 2, 2026
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.

Bug: SSH tunnel not restarted on unexpected exit

2 participants