Skip to content

Skip unroutable IP families before dialing#134

Merged
JamieMagee merged 1 commit into
mainfrom
fix/symmetric-ip-family-filtering
Jun 4, 2026
Merged

Skip unroutable IP families before dialing#134
JamieMagee merged 1 commit into
mainfrom
fix/symmetric-ip-family-filtering

Conversation

@JamieMagee
Copy link
Copy Markdown
Member

What are you trying to accomplish?

On IPv4-only hosts the proxy still tried IPv6 addresses returned by DNS, hung until the socket timed out, and that cascaded into the updater's 100s HttpClient.Timeout. Now we drop addresses whose family the host can't route before dialing, so single-stack hosts fail fast. IPv6-only hosts had the same problem with IPv4 addresses, so both families get the same treatment.

Anything you want to highlight for special attention from reviewers?

The probe is a connected UDP dial to a documentation address (192.0.2.1 / 2001:db8::1). It checks for a route, not real reachability, and caches the result for the process lifetime. A blackhole route could still report "available" (same caveat for both families).

How will you know you've accomplished your goal?

go test ./internal/dialer/ passes, including new cases: IPv4-only keeps only IPv6, IPv6-only keeps only IPv4, and neither available returns ErrNoUsableAddress without dialing.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@JamieMagee JamieMagee requested a review from a team as a code owner June 3, 2026 16:21
Copilot AI review requested due to automatic review settings June 3, 2026 16:21
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the proxy’s TCP dialing behavior on single-stack hosts by filtering out DNS-resolved IPs whose address family the host can’t route, avoiding long socket timeouts and reducing cascading request timeouts in upstream clients.

Changes:

  • Added IPv4/IPv6 “route availability” probes (cached for process lifetime) and filtered resolved IPs accordingly before dialing.
  • Introduced ErrNoUsableAddress to fail fast when DNS returns only unusable addresses for the requested network.
  • Added unit tests covering single-stack behavior, requested network filtering (tcp4/tcp6), and “neither family available” cases.
Show a summary per file
File Description
internal/dialer/dialer.go Filters resolved IPs by routable family before dialing; adds availability probes and a new error for “no usable address”.
internal/dialer/dialer_test.go Adds tests validating address-family filtering and error behavior without attempting any real dials.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread internal/dialer/dialer.go
Comment on lines +68 to 72
ips, err = d.usableIPs(network, host, ips)
if err != nil {
return nil, err
}
for _, ip := range ips {
Comment on lines +14 to +22
func TestDialContextSkipsIPv6WhenUnavailable(t *testing.T) {
dialer, dialed := testDialer([]string{"2001:db8::1", "192.0.2.1"}, false)

conn, err := dialer.DialContext(context.Background(), "tcp", "example.com:443")
require.NoError(t, err)
require.NotNil(t, conn)

assert.Equal(t, []string{"192.0.2.1:443"}, *dialed)
}
@JamieMagee JamieMagee force-pushed the fix/symmetric-ip-family-filtering branch from 925e48f to 74734c6 Compare June 3, 2026 20:00
Comment thread internal/dialer/dialer.go
@JamieMagee JamieMagee merged commit 32a6545 into main Jun 4, 2026
104 checks passed
@JamieMagee JamieMagee deleted the fix/symmetric-ip-family-filtering branch June 4, 2026 20:27
@yeikel
Copy link
Copy Markdown

yeikel commented Jun 8, 2026

I am guessing that this superseded and made #124 redundant, right?

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.

5 participants