Skip to content

fix(shared): port test uses an IPv4 address the machine can reach itself - #43794

Closed
gilitos92 wants to merge 1 commit into
pingdotgg:mainfrom
gilitos92:fix/net-test-reachable-ipv4-upstream
Closed

gilitos92 wants to merge 1 commit into
pingdotgg:mainfrom
gilitos92:fix/net-test-reachable-ipv4-upstream

Conversation

@gilitos92

Copy link
Copy Markdown
Contributor

Note

Written by Claude Opus 5.5 on behalf of Gil.

Problem

findAvailablePort falls back when a wildcard listener occupies IPv4 (packages/shared/src/Net.test.ts) fails on a Mac whose first non-loopback IPv4 address belongs to a tunnel the machine cannot dial itself. The test takes the first non-internal IPv4 address from os.networkInterfaces() and assumes a connection to its own listener there succeeds. With the NextDNS app running, that address is the tunnel placeholder 192.0.2.42 on utun4: packets to it go into the DNS-only tunnel and are dropped, so hasListenerOnHost times out. macOS also lets a specific-address bind succeed next to a wildcard listener, so findAvailablePort keeps the occupied port and the assertion notEqual(resolved, preferred) fails.

No configuration change is needed to hit it: macOS appends a re-attached interface to the end of its list, so after a Wi-Fi driver restart en0 moves behind existing tunnels and the test starts failing.

Change

The test now uses the first non-internal IPv4 address whose own listener accepts a connection within 250 ms (the same timeout hasListenerOnHost uses). Only the test changes; Net.ts is unchanged. On Linux CI the first address is already reachable, so the chosen address is the same as before.

Scope

A small fix for an obvious test bug, so no issue. It breaks vp test in packages/shared on macOS machines with a tunnel listed before Wi-Fi.

Verification

On macOS 27 with NextDNS (utun4 = 192.0.2.42) listed before en0 (10.0.0.198), vp test run src/Net.test.ts in packages/shared:

  • Before: findAvailablePort falls back when a wildcard listener occupies IPv4 fails (expected 58018 to not equal 58018).
  • After: it passes, and the probe picks 10.0.0.198.

The two tests from #43478 (findAvailablePort skips a port a LAN listener holds for wildcard host "0.0.0.0" and "") fail on this Mac before and after this change. That is a separate macOS issue and not part of this PR.

Written with Claude Opus 5.5 in Claude Code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The test setup now checks whether each non-internal IPv4 address can connect to a temporary server bound to that address. It selects the first reachable address and leaves ownIpv4 undefined if none succeeds.

Changes: IPv4 test setup

Layer / File(s) Summary
IPv4 reachability selection
packages/shared/src/Net.test.ts
The setup checks non-internal IPv4 addresses in order. Bind errors, connection errors, and 250 ms timeouts mark an address unreachable. The first successful connection sets ownIpv4; if none succeeds, it remains undefined.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: datuzzo, stienswout

Merge Risk: Minimal · up to 07b5d

This only changes how a test picks a local IPv4 address, so it makes the test more robust on machines with DNS-only tunnel interfaces. Production behavior is unaffected, and the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the port test now picks an IPv4 address the machine can reach itself. It matches the raw summary, which describes selecting ownIpv4 by testing that a temporary listene…
Description check Passed The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specifics. The Problem section names the failing test and the macO…
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.
Full details: Title check

Explanation

The title names the main change: the port test now picks an IPv4 address the machine can reach itself. It matches the raw summary, which describes selecting ownIpv4 by testing that a temporary listener accepts a connection. The title is specific and uses a conventional commit prefix.

Full details: Description check

Explanation

The description follows the repository template. It has Problem, Change, Scope, and Verification sections, and each is filled in with specifics. The Problem section names the failing test and the macOS tunnel cause. The Change section explains the timeout and that Net.ts is unchanged. The Scope section explains why no issue is linked. The Verification section gives before and after results on macOS 27 and notes the two unrelated failing tests. It also includes the model attribution the template asks for. The description does not link an issue, but it explains why none is needed, which the template accepts.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between f4b2523 and 07b5deb.

Files selected for processing: 1

  • packages/shared/src/Net.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@gilitos92 gilitos92 closed this Nov 26, 2026
@gilitos92
gilitos92 deleted the fix/net-test-reachable-ipv4-upstream branch November 26, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant