Jaa


Slow localhost connections in WCF

I do a lot of WCF development on my laptop and I noticed that connections to my test services on my laptop were suddenly taking a really long time to execute. Further review showed that it was the initial connection which was taking up all this time (about 20 seconds or so). The problem surfaced even when hitting a simple ASPX page on my IIS7 web server (running on Windows Vista) from Internet Explorer or FireFox. So the problem had nothing to do with WCF. All these things pointed to one problem - name lookups. But localhost isn't supposed to be looked up right? Turns out that it does do one lookup - in the hosts table which is located in \windows\system32\drivers\etc\hosts. I looked in there and found this really weird entry:

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

127.0.0.1       localhost
::1 localhost

Notice there are two entries for localhost and the second entry would almost certainly give some sort of trouble. The first entry should be the only required mapping for localhost. Once I removed the offending entry and issued a nbtstat -R command (which reloads the name cache) all was good with the world again!

Now if only someone can tell me how this entry got into my hosts file ... my hunch is that it is related to IPV6 but would like to have someone confirm that.