Skip to content

fix(ssh): resolve PR #37 issues — dedup, context-aware connect, reconnect coalescing#38

Merged
zx06 merged 2 commits intomainfrom
pr-37-fix-ssh-reconnect-20260325141000
Mar 25, 2026
Merged

fix(ssh): resolve PR #37 issues — dedup, context-aware connect, reconnect coalescing#38
zx06 merged 2 commits intomainfrom
pr-37-fix-ssh-reconnect-20260325141000

Conversation

@zx06
Copy link
Copy Markdown
Owner

@zx06 zx06 commented Mar 25, 2026

Summary:\n- Deduplicated SSH options and improved SSH Connect to use context-aware dialer.\n- Rewrote reconnect logic to coalesce concurrent reconnects, reduce locking, and restart keepalive loops.\n- Added in-process SSH server tests and extensive reconnect/keepalive unit tests under internal/ssh.\n\nFiles changed: internal/app/conn.go, internal/ssh/client.go, internal/ssh/reconnect.go, internal/ssh/client_test.go, internal/ssh/reconnect_test.go, internal/ssh/testutil_test.go\n\nRun tests locally: go test ./... -race\n

…nect coalescing

Fix remaining issues from PR #37 (SSH keepalive & auto-reconnect):

1. Eliminate code duplication: ResolveConnection() now uses resolveSSHOptions()
   instead of duplicating SSH options construction (fixes SonarQube 3.1% > 3%)

2. Context-aware SSH Connect: Replace ssh.Dial() with net.DialContext() +
   ssh.NewClientConn() so context cancellation/timeout interrupts both
   TCP connection and SSH handshake phases

3. Reconnect coalescing: Multiple concurrent DialContext/keepalive failures
   trigger a single reconnect instead of racing. Lock released during retry
   loop to avoid blocking other DialContext callers

4. Keepalive recovery: Keepalive monitoring restarts after failed reconnect
   attempts, preventing permanent loss of health detection

5. In-process SSH test server: testutil_test.go provides a real SSH server
   (using golang.org/x/crypto/ssh) for testing connect, keepalive, tunnel
   forwarding, and reconnection — runs on all platforms without Docker

Test coverage: internal/ssh 87.6% → 93.9%, internal/app 85.1% → 85.5%

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

❌ Patch coverage is 92.45283% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.65%. Comparing base (a18431f) to head (d1a28aa).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
internal/ssh/reconnect.go 92.50% 2 Missing and 1 partial ⚠️
internal/ssh/client.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
+ Coverage   80.97%   81.65%   +0.68%     
==========================================
  Files          41       41              
  Lines        2901     2933      +32     
==========================================
+ Hits         2349     2395      +46     
+ Misses        423      410      -13     
+ Partials      129      128       -1     
Flag Coverage Δ
e2e 44.09% <ø> (ø)
integration 44.09% <ø> (ø)
unittests 69.86% <92.45%> (+0.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Handle errcheck: use _ = for SetDeadline/Close return values in client.go
- Fix goimports: remove trailing blank line in reconnect.go
- Fix test auth: generate temp ed25519 key file in testutil_test.go so
  tests pass in CI environments without ~/.ssh keys

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@zx06 zx06 merged commit 60a3a39 into main Mar 25, 2026
14 checks passed
@zx06 zx06 deleted the pr-37-fix-ssh-reconnect-20260325141000 branch March 25, 2026 07:03
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.

1 participant