Chrome Slow to Resolve /etc/hosts on macOS / OS X

9

Our developers use either Docker or VirtualBox (with Vagrant) to test their code locally (and the problem happens with both). To facilitate this, we modify /etc/hosts to point to the correct IP address. For example,

local.test.company.com 10.200.10.1

Some of our developers are on Linux and some are on macOS Sierra (10.12.3). On Mac, requests to local.test.company.com in Chrome (and other browsers) often take a long time (up to a minute or more) to resolve. (The problem doesn't happen on Ubuntu Linux.) During this time, the "loading icon" on the tab is the gray icon spinning to the left. As soon as it changes to the blue icon spinning to the right, it finishes very quickly. The slow loading time can be a real problem for our developers who often refresh the site during development.

Based on this question, it seems that Chrome is taking a full minute to resolve the site. This doesn't make sense to me - a site in /etc/hosts should resolve immediately. Some developers can reproduce this behavior very consistently. Others see it intermittently or don't see it at all, and I have not been able to figure out why.

Why do the requests to local.test.company.com take a long time to resolve in a web browser?

Or, what can I do to "debug" this problem and figure out what's taking so long?


Additional Notes

  • The behavior continues to happen with Chrome in "incognito mode" with "disable cache" turned on.
  • ping resolves local.test.company.com immediately.

mkasberg

Posted 2017-03-16T17:08:23.283

Reputation: 1 413

Answers

0

I eventually figured this out. As it turns out, Chrome is not necessarily resolving while the circle is spinning to the left. The circle on chrome spins to the left during data upload and to the right during data download.

I figured this out by debugging the PHP application that was being run in Chrome. PHP responds to a request from Chrome, the circle in Chrome continues spinning to the left until the first print statement in PHP. That is, until the server sends the first byte of data back to the client.

So, in summary, this was not a problem with DNS resolution at all. DNS was fine, our web application was simply not sending any data back as quickly as we thought it would (either due to being paused in the debugger or for other reasons).

mkasberg

Posted 2017-03-16T17:08:23.283

Reputation: 1 413

11

I had the same issue in Chrome 64.0.3282.167 on macOS High Sierra (10.13.3) and this StackOverflow answer solved it for me:

https://stackoverflow.com/a/10200111/318359

Quote:

Put all your hosts file entries for localhost into one line like so:

127.0.0.1 localhost myproject.dev myotherproject.dev 
::1 localhost

Burnash

Posted 2017-03-16T17:08:23.283

Reputation: 211

1

Thank you, thank you! Been putting up with this for so long! There's also an interesting answer there regarding .local addresses being checked with bonjour before DNS: https://stackoverflow.com/a/17982964/2778502

– jeff-h – 2018-04-10T02:34:32.753

2

mooyah

Posted 2017-03-16T17:08:23.283

Reputation: 21

Great suggestion! I'll give it a shot & see how it goes. – mkasberg – 2017-03-17T16:28:04.363

You can also try to use "instruments" which gives a better visualization. – mooyah – 2017-03-17T19:43:30.940

1Although your answer is 100% correct, it might also become 100% useless if that link is moved, changed, merged into another one or the main site just disappears... :-( Therefore, please [edit] your answer, and copy the relevant steps from the link into your answer, thereby guaranteeing your answer for 100% of the lifetime of this site! ;-) You can always leave the link in at the bottom of your answer as a source for your material... – Donald Duck – 2017-03-18T09:05:52.033