Firefox is slow to resolve localhost domains on MacOS, Chrome is not

2

I am developing a website on localhost with the following entry in my hosts file:

192.168.10.10  mysite.local

That IP is coming from a Vagrant provisioned VM hosted in Virtualbox.

Whenever I try to load the site in Firefox, it takes about 3-4 seconds before it is able to resolve the domain. I see looking up mysite.local in the lower left of Firefox for a while, then it loads the site quickly. Each subsequent lookup happens quickly as if it has cached that DNS lookup,

However, if I let the site go idle for about 5 minutes, the lookup is slow again.

Chrome and Safari do not have this problem. They both always resolve the domain quickly, even from a cold start. Firefox is the only one that struggles with it.

What can I do to troubleshoot what might be causing this problem in Firefox?

EDIT: It looks like Firefox caches DNS lookups for 60 seconds (according to about:config, which explains why the site is resolved quickly if I continually use it, but goes back to being slow if I let it sit idle. So the question then becomes, why is only Firefox having trouble resolving it when it's not cached?

AgmLauncher

Posted 2019-06-13T00:30:34.017

Reputation: 131

What is the response time of you open the Terminal and run ping mysite.local or even curl -I mysite.local? Also, what is the web server you are using on your VM? Apache? Nginx? Something else? – JakeGould – 2019-06-13T00:33:54.833

Response time for ping mysite.local is 0.3 seconds on average. Nginx is the webserver. – AgmLauncher – 2019-06-13T00:37:50.557

1Do you have DNS over HTTPS enabled? Go to about:preferences and check the Network Settings at the bottom of General. Or go to about:config and check network.trr.mode. – Bob – 2019-06-13T00:47:53.213

@Bob No, it is disabled (I didn't set this, it was just that way when I checked the settings). Enabling it fixed the problem though! What are the security ramifications of enabling DNS over HTTPs? – AgmLauncher – 2019-06-13T00:50:24.167

That's... rather odd. I would expect this kind of problem if DNS over HTTPS is enabled, because it'll directly query a specific external DNS server (CloudFlare, by default) rather than use the local OS resolver, and therefore ignore /etc/hosts. In that scenario, disabling DNS over HTTPS would fix your issue. Enabling it, on the other hand, shouldn't... try disabling it again and see what happens? What specifically is network.trr.mode set to? (there's a "auto-pick fastest" and a "try doh but fallback on timeout" option, which is what I originally suspected was your issue) – Bob – 2019-06-13T00:53:02.253

I agree, it's odd. If I enable DNS over HTTPS via the UI in about:preferences, it sets network.trr.mode to 2 and shows as modified. If I disable the option via about:preferences it gets set to 0. Looks like maybe I spoke too soon. After disabling it, and then re-enabling it, I am having the same issue as before. The first time I enabled it, it did fix the problem. – AgmLauncher – 2019-06-13T00:56:52.113

And if you disable (on 0) you experience this problem again? On 2 it should try DNS over HTTPS, fail to resolve this domain, and fall back to trying native - which I would've expected to introduce the delay you experience. On 0 it should be full native, without the delay. – Bob – 2019-06-13T00:58:12.927

Oddly, I now experience this problem again with both 0 and 2. The first time I enabled it, I did so via the UI. I don't know what the actual value was at that time, but it did fix the issue. It was only when I disabled it to test it, and then re-enable it, that it went back to being problematic. So as it stands now, both 0 and 2 exhibit the same problem. Very odd. – AgmLauncher – 2019-06-13T01:00:46.230

You may have just been within the cached period. Leave DNS over HTTPS off for now. Just for kicks, can you try a different TLD? One other than .local? I wonder if mDNS is involved. Try both a nonexistent one like mysite.qwertyasdf and a "real" one like mysite.com. – Bob – 2019-06-13T01:01:15.517

You can also poke around in about:networking, especially the "Logging" tab, and see if you can identify anything odd. – Bob – 2019-06-13T01:08:32.197

Instead of relying on editing your /etc/hosts file, I would recommend installing Avahi deamon on your VM and let it handle the mDNS. The hostname would be the machine name of the VM, FWIW. So if the machine is named mysite then mysite.local would work as expected.

– JakeGould – 2019-06-13T01:09:50.783

1@Bob I took your advice, and Firefox doesn't like .local as a domain. I used .qwerty and it worked fine. I created several dummy sites on that VM, some with .local and some with .qwerty and all of the .local domains were slow, while .qwerty was fast. .com would not work (it always tried to resolve actual internet domains for them). I used to use .dev, but Chrome killed that so I switched to .local, which Firefox hates. Sigh. Thanks for the help though. The resolution is to change the TLD to something FF friendly. If you want to create an answer for your comment, I'll accept. – AgmLauncher – 2019-06-13T01:17:12.930

No answers