Tuesday, March 10, 2009

Localhost suddenly broken and I'm blaming Windows Update

Wow, it's been absolute ages since I last posted. SO much has happened since my last post. CentraStage is going very well. We're growing from strength to strength but easy does it nicely.

Anyway, today I just wanted to quickly note a frustration I experienced today. After months of never having any trouble using 'localhost' as a reference to my Tomcat instance, or my local database, 'localhost' suddenly broke. Kaput! Dood! Every time I tried to use localhost the connection was refused. I Googled this and found a variety of potential reasons, none of them all that encouraging since they had very little to do with anything I used on my machine.

A number of posts referred to entries in the hosts file, but these referred to the /etc/hosts file in Unix/Linux-land. Nevertheless, there is a Windows hosts file buried in %windir%\system32\drivers\etc\hosts. So I looked at that file and there was a single entry:

::1 localhost

Many Google posts had another line as a translation of localhost to 127.0.0.1. What was peculiar is that if I used 127.0.0.1 in place of localhost in my apps, it would work fine. So something seemed wrong with my translation. Yet I had done nothing that should have affected this, and the hosts file itself was last changed in September 2006.

I conferred with a colleague who indicated that he had the two entries as I'd seen in some of the Google posts, but both of his entries were commented out. After trying numerous things, including attempting to roll back to a system restore point prior to my most recent Windows Update (which as far as I'm concerned is when things started misbehaving) - an exercise that was futile since all my restore points are benign (Windows says there was a problem rolling back and that no changes were made) - I decided to have a go at changing the hosts file.

Look no further than: http://support.microsoft.com/default.aspx?scid=kb;en-us;923947 for how to do this. So I commented out the one line that referred to localhost, restarted my app, and baddabing, baddaboom - it all just worked.

So I have no idea what caused this problem, but needless to say it disabled me for the day. I still strongly suspect the Windows Update that ran this morning, but I'll never really know. But it's fixed now thank goodness for that!