Skip to content

fix: bound and cancel discovery probes - #23

Merged
Luqueee merged 8 commits into
mainfrom
codex/reject-unknown-config
Sep 4, 2026
Merged

Luqueee merged 8 commits into
mainfrom
codex/reject-unknown-config

Conversation

@Luqueee

@Luqueee Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary\n\n- bound every candidate probe to a five-second deadline\n- propagate the auto-discovery context through Probe and the SSH tunnel\n- stop all probes promptly when the discovery cycle is cancelled\n- add cancellation, timeout, and SSH DialContext regression tests\n\nCloses #13\n\n## Validation\n\n- 170 Go tests passed\n- race tests passed\n- go vet passed\n- gofmt and diff checks passed

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Configuration files now reject unknown settings and multiple YAML documents with clearer, path-specific errors.
    • Empty YAML configuration files continue to preserve default settings.
    • Discovery operations now respond to cancellation and stop stalled probes after a timeout.
    • Tunnel connection attempts now honor cancellation and expiration, returning promptly without unnecessary reconnect attempts.
    • Temporary connection resources are cleaned up when canceled or when connection attempts fail.
  • Reliability

    • Improved behavior for interrupted or blocked connection attempts during device discovery and tunnel operation.

Walkthrough

Changes

The pull request adds context cancellation to discovery and tunnel dialing. It adds per-probe timeouts, bounded probing, transport cleanup, and stricter YAML validation. Tests cover cancellation, timeout, defaults, unknown keys, and multiple documents.

Context-aware network operations

Layer / File(s) Summary
Context-aware discovery probing
internal/discover/discover.go, internal/discover/discover_test.go
Dialer and Probe now accept contexts. Probes use five-second timeouts, bounded concurrency, cancellation checks, and late-connection cleanup.
Auto-discovery context propagation
cmd/mole/main.go
Initial and periodic auto-discovery pass the active context through discoverInto to ProbeWithFactory.
Context-aware tunnel dialing
internal/tunnel/tunnel.go, internal/tunnel/reconnect_test.go
Manager.DialContext propagates cancellation through SSH transport setup, channel opens, reconnect coordination, retries, and ProxyJump connections. Tests cover cleanup, deadlines, and cancellation.

Strict YAML configuration loading

Layer / File(s) Summary
YAML document validation
internal/config/config.go, internal/config/config_test.go
Load rejects unknown fields and additional YAML documents, accepts empty documents, and preserves configuration paths in errors.

Merge Risk: 🟡 Moderate · up to 8e8aa

Failed probe transport setup can appear as an empty discovery result, masking unavailable remote discovery. Port order can also vary between equivalent sweeps. Resolve these before merge.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required Conventional Commit format with the fix: prefix and clearly describes the bounded, cancellable discovery probe changes.
Description check ✅ Passed The description directly summarizes probe timeouts, context propagation, cancellation, transport reuse, concurrency limits, regression tests, and validation results.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/reject-unknown-config

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/tunnel/tunnel.go (1)

197-197: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Make reconnect and SSH transport dialing honor ctx.

After the context check, reconnect can wait on reconnectMu and m.connect can invoke context-free m.dial. dialRemote uses ssh.Dial and context-free ProxyJump operations; the 10-second SSH timeout does not bound lock waits or every handshake. DialContext can therefore outlive its deadline. Make lock acquisition cancellable and propagate ctx through every transport and ProxyJump operation, including cancellation cleanup.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 11c13fad-38fb-46e0-af63-b7262853ecb8

📥 Commits

Reviewing files that changed from the base of the PR and between 234f284 and 2bd4cf5.

📒 Files selected for processing (7)
  • cmd/mole/main.go
  • internal/config/config.go
  • internal/config/config_test.go
  • internal/discover/discover.go
  • internal/discover/discover_test.go
  • internal/tunnel/reconnect_test.go
  • internal/tunnel/tunnel.go

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread internal/tunnel/tunnel.go Outdated
@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully

Fixed 2 CodeRabbit findings in 2 files.

Files modified:

  • internal/tunnel/tunnel.go
  • internal/tunnel/reconnect_test.go

Commit: 7cbd792

The latest autofix changes are on the codex/reject-unknown-config branch.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 8082656f-64d7-4d12-8c90-955dd5aa9202

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd4cf5 and 7cbd792.

📒 Files selected for processing (2)
  • internal/tunnel/reconnect_test.go
  • internal/tunnel/tunnel.go

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread internal/tunnel/tunnel.go
Comment thread internal/tunnel/tunnel.go
Comment thread internal/tunnel/tunnel.go Outdated
@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully

Addressed the CodeRabbit performance finding about one SSH handshake per discovery probe.

Changes:

  • reuse one temporary SSH transport per discovery sweep
  • cap concurrent probes at four
  • bound the sweep to five seconds and close the transport after all workers finish
  • add coverage for transport reuse and concurrency limits

Files modified:

  • cmd/mole/main.go
  • internal/discover/discover.go
  • internal/discover/discover_test.go
  • internal/tunnel/tunnel.go

Commit: 366172c

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully

Addressed the CodeRabbit finding Restore config.Timeout for SSH TCP connects.

Changes:

  • apply ClientConfig.Timeout to context-aware TCP dialing
  • bound SSH handshakes even when the caller uses context.Background()
  • close the raw connection and wait for the handshake goroutine on timeout
  • add a regression test for the bounded handshake

Files modified:

  • internal/tunnel/tunnel.go
  • internal/tunnel/reconnect_test.go

Commit: 8e8aa01

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Team

Run ID: 8fd62fe3-9ca5-41d3-96a6-ba1c7792a9bb

📥 Commits

Reviewing files that changed from the base of the PR and between 7cbd792 and 8e8aa01.

📒 Files selected for processing (5)
  • cmd/mole/main.go
  • internal/discover/discover.go
  • internal/discover/discover_test.go
  • internal/tunnel/reconnect_test.go
  • internal/tunnel/tunnel.go

Included review availability: Your plan provides up to 8 included reviews per hour; 2 remain after this review.

Comment thread internal/discover/discover.go Outdated
Comment thread internal/discover/discover.go
@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Fixes Applied Successfully

Addressed the CodeRabbit Major finding Return sweep transport setup errors to the caller.

Changes:

  • ProbeWithFactory now returns the discovered ports together with setup errors
  • transport creation failures are wrapped and preserved for errors.Is
  • discoverInto logs the failure and leaves the current forwarding set unchanged
  • added regression coverage for transport setup errors

Files modified:

  • cmd/mole/main.go
  • internal/discover/discover.go
  • internal/discover/discover_test.go

Commit: ee61c07

@Luqueee

Luqueee commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit fix applied

Addressed the remaining deterministic-order finding:

  • sort the discovered ports after the bounded worker sweep completes
  • add a regression test with intentionally out-of-order probe completion

Validation: go test ./..., go test -race ./..., go vet ./..., and git diff --check all pass.

Commit: 28ae137

@Luqueee
Luqueee merged commit 03db9ab into main Sep 4, 2026
4 checks passed
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