Skip to content

Avoid getfqdn to speed things up on MacOS - #106

Merged
astrofrog merged 9 commits into
astropy:mainfrom
astrofrog:avoid-getfqdn
Oct 22, 2026
Merged

astrofrog merged 9 commits into
astropy:mainfrom
astrofrog:avoid-getfqdn

Conversation

@astrofrog

@astrofrog astrofrog commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

The short version is, getfqdn is really slow on Mac (it's slow locally and very slow in CI), so this switches to a different way to check if an IP is local, which should be equivalent (no changes needed to the tests).

This also caches the allowed hosts once per process to make that part faster too (_resolve_host_ips)

AI disclosure: helped by Claude Opus 5.5

Fix #90

Fix #103

Comment thread CHANGES.rst
@pllim

pllim commented Oct 22, 2026

Copy link
Copy Markdown
Member

Would also speed up CI if you reduce the number of jobs by addressing #103 😉

@astrofrog
astrofrog requested a review from pllim October 22, 2026 21:48
@astrofrog

Copy link
Copy Markdown
Member Author

@pllim - think this is ready!

pllim
pllim previously approved these changes Oct 22, 2026

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment thread tox.ini
check_internet_off called socket.gethostname() and socket.getfqdn() on
every intercepted bind/connect/create_connection. getfqdn() does a reverse
DNS lookup of the local hostname, which takes ~35 s per call on GitHub's
macOS runners, making the test suite take up to 15 minutes per tox command
there (vs ~30 s on Linux).

Connections to the machine's own hostname are still redirected to
localhost, using only the cheap gethostname() call. Connections to any
other name that resolves to a local interface (e.g. the FQDN) are now
detected by attempting to bind to the resolved address, which only
succeeds for local interfaces and requires no reverse DNS lookup.
The IPs of the allowed GitHub/Astropy data hosts were resolved on every
intercepted socket call, so e.g. --remote-data=astropy did over 100 DNS
lookups per test run. Cache _resolve_host_ips so each host is resolved
once per process.
The hostname parameter only works when the blocker redirects the
machine's own name to localhost; with --remote-data=any the blocker is
off and the connection went to the LAN address, where the test server
bound to localhost is not listening.
HTTPServer.server_bind calls socket.getfqdn() on the bound address, which
takes ~35 s for the first call on GitHub's macOS runners and made
test_localconnect_succeeds[localhost] the slowest test in the suite.
@astrofrog

Copy link
Copy Markdown
Member Author

@pllim rebased and added back pytestoldest in 96b8d29

@astrofrog
astrofrog requested a review from pllim October 22, 2026 22:10
Comment thread tox.ini
@pllim
pllim dismissed their stale review October 22, 2026 22:19

Comment needs resolving first.

@astrofrog

Copy link
Copy Markdown
Member Author

@pllim How's this?

@astrofrog
astrofrog requested a review from pllim October 22, 2026 22:25

@pllim pllim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM now. Thanks!

@pllim

pllim commented Oct 22, 2026

Copy link
Copy Markdown
Member

I gotta run. Feel free to merge!

@astrofrog
astrofrog merged commit 5fbdce7 into astropy:main Oct 22, 2026
12 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.

Drop Python 3.9 and 3.10 TST: Investigate why OSX jobs take 40 mins instead of 40 secs

2 participants