[Macos/Apple M1] HTTP client requests to ".local" domain adds 5 seconds overhead

299 views
Skip to first unread message

Jonathan Hedrén

unread,
Mar 31, 2021, 1:05:50 PM3/31/21
to golang-nuts
I've set up a development environment on my MacBook Pro M1 (running Big Sur 11.2.3, Go 1.16.2) with a number of small Go/.Net HTTP APIs that are communication with each other. To replicate our production infrastructure I've set up /etc/hosts with ".local" domains pointing to 127.0.0.1. An nginx server then proxies the requests to the APIs. A self signed certificate is used for https.

Whenever an HTTP request is sent from a Go application to any of the ".local" APIs, 5 seconds are added to the response time. This delay is not added when I use a browser to make the request, neither if I call an external address (for example google.com) or "localhost" from the Go code. It only happens when I use http.Client to request a ".local" domain and the behavior is consistent. 

I've searched the Go standard library for a "5 * time.Second" and found it only in a few places, including src/net/dnsconfig_unix.go so I guess it's related to the name resolution.

Anyone got an idea about what's wrong and how it can be fixed? 

/Jonathan

Wojciech S. Czarnecki

unread,
Mar 31, 2021, 5:57:05 PM3/31/21
to golan...@googlegroups.com, Jonathan Hedrén
Dnia 2021-03-31, o godz. 01:47:43
Jonathan Hedrén <jonatha...@gmail.com> napisał(a):

> Whenever an HTTP request is sent from a Go application to any of the
> ".local" APIs, 5 seconds are added to the response time.

https://www.bram.us/2011/12/12/mamp-pro-slow-name-resolving-with-local-vhosts-in-lion-fix/

TL;DR do NOT use .local; keep hosts entries under allowed 10 names.

Hope this helps,

--
Wojciech S. Czarnecki
<< ^oo^ >> OHIR-RIPE

Shulhan

unread,
Apr 1, 2021, 1:40:10 AM4/1/21
to Jonathan Hedrén, golang-nuts

Jonathan Hedrén

unread,
Apr 1, 2021, 2:49:16 AM4/1/21
to golang-nuts
Thanks! I added the IPv6 loopback address to all my host names in /etc/hosts (i.e. "::1 mydomain.local") and it now works as expected. 

I guess Go's DNS resolver was timing out at the first attempt, that's why I consistently had that 5 second delay.
Reply all
Reply to author
Forward
0 new messages