Skip to content

refactor: extract Dialer interface to decouple proxy logic from tsnet#12

Merged
mlorentedev merged 1 commit into
masterfrom
refactor/dialer-interface
Mar 8, 2026
Merged

refactor: extract Dialer interface to decouple proxy logic from tsnet#12
mlorentedev merged 1 commit into
masterfrom
refactor/dialer-interface

Conversation

@mlorentedev
Copy link
Copy Markdown
Owner

Summary

  • Extract Dialer interface (Dial(ctx, network, addr) → net.Conn) so acceptLoop and handleConn no longer depend on *tsnet.Server directly
  • tsnet.Server satisfies the interface implicitly — zero adapter code needed
  • Fix pre-existing data race in proxyConnections where the rx goroutine could still write after the function returned byte counts (added sync.WaitGroup)
  • Add "closed pipe" to expected close errors (pipe analog of ECONNRESET)

Changes

  • main.go: +6 lines Dialer interface, signature updates, WaitGroup fix
  • main_test.go: +3 new tests (TestDialerInterfaceSatisfaction, TestHandleConnWithDialer, TestAcceptLoopWithDialer)
  • main_integration_test.go: +1 test case for closed pipe error classification

Testing

  • go test -race -count=5 ./... — 0 failures, 0 races
  • go vet ./... clean
  • go build ./... clean

Type

  • refactor — Code restructuring (no behavior change)
  • fix — Bug fix (proxyConnections race condition)

ARCH-001 from Stream E roadmap. Enables ARCH-003 (mock-based proxy tests) and ARCH-004 (reconnection logic).

Replace *tsnet.Server with Dialer interface in acceptLoop and handleConn,
enabling mock-based testing of core proxy logic without a Tailscale network.
tsnet.Server satisfies the interface implicitly — no adapter needed.

Also fixes a pre-existing data race in proxyConnections where the rx
goroutine could still be writing when the function returned byte counts.
@mlorentedev mlorentedev merged commit 40ac4b9 into master Mar 8, 2026
11 checks passed
@mlorentedev mlorentedev deleted the refactor/dialer-interface branch March 8, 2026 02:12
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