Skip to content

Skip interfaces that have no address - #25

Merged
colemancda merged 1 commit into
mainfrom
fix/null-interface-address
Aug 7, 2026
Merged

Skip interfaces that have no address#25
colemancda merged 1 commit into
mainfrom
fix/null-interface-address

Conversation

@colemancda

Copy link
Copy Markdown
Member

getifaddrs reports an entry with a null ifa_addr for an interface that has no address assigned — a tunnel device, for instance. NetworkInterface.interfaces read sa_family straight through that pointer, so enumerating interfaces trapped with "Unexpectedly found nil while implicitly unwrapping an Optional value" on any host that has one.

The #if os(Android) branch immediately above already handled exactly this case; the fix is to use that form on every platform and delete the branch. The line just below (value.ifa_addr.flatMap { ... }) already treated the pointer as nullable, so this makes the two consistent.

Testing

Reproduces on a machine with a tailscale interface: swift test crashed the test process at NetworkInterface.swift:58, taking down the whole run.

With the fix, swift test --no-parallel passes 25/25 on Linux — the three testNetworkInterface* tests now run rather than aborting the process, which is why the count is up from the 22 that previously survived.

CI never caught this because the GitHub runners have no addressless interface.

getifaddrs reports an entry with a null ifa_addr for an interface that has no
address assigned, such as a tunnel, so reading sa_family through it trapped
while enumerating. Android already guarded for this; every platform needs it.
@colemancda
colemancda merged commit 5cddb5e into main Aug 7, 2026
37 checks passed
@colemancda
colemancda deleted the fix/null-interface-address branch August 7, 2026 03:24
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