Skip to content

fix(macos): return interfaces instead of crashing when out of file descriptors - #203

Merged
shellrow merged 1 commit into
shellrow:mainfrom
GeiserX:fix/macos-fd-exhaustion
Nov 28, 2026
Merged

shellrow merged 1 commit into
shellrow:mainfrom
GeiserX:fix/macos-fd-exhaustion

Conversation

@GeiserX

@GeiserX GeiserX commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #202.

On macOS, get_interfaces() crashes the process with SIGSEGV when the process has no free file descriptors. The plist read fails with EMFILE, and interfaces() then falls back to get_sc_interface_map(). In that state SCNetworkInterfaceGetLocalizedDisplayName crashes inside CoreFoundation (the backtrace is in the issue).

This change skips the SystemConfiguration fallback when the plist read fails with EMFILE or ENFILE. interfaces() then returns the interfaces from getifaddrs without the SC metadata: no friendly name and no DHCP flags. Every other plist error still takes the fallback, as before.

Testing

On a Mac mini with macOS 26.6.1, I used the repro from the issue with ulimit -n 256. It also calls get_interfaces() a second time after it frees the descriptors:

Build With all descriptors used After they are freed
netdev 0.48.0 from crates.io exit 139 (SIGSEGV) not reached
this branch 31 interfaces, exit 0 31 interfaces, 9 with a friendly name
  • cargo test, cargo test --all-features and cargo test --no-default-features pass. They include a new unit test for the EMFILE/ENFILE check.
  • cargo fmt --all --check is clean.

…scriptors

When the process has no free descriptors, the plist read fails with EMFILE and
the fallback to SCNetworkInterfaceCopyAll crashes inside CoreFoundation. Return
the interfaces without SC metadata instead.

Fixes shellrow#202
@shellrow

Copy link
Copy Markdown
Owner

Thanks for the fix and verifying!

@shellrow
shellrow merged commit cbdb6eb into shellrow:main Nov 28, 2026
6 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.

macOS: get_interfaces() segfaults when the process has run out of file descriptors

2 participants