Wednesday, December 26, 2007

Coldfusion caches IP addresses -- so watch out when you change DNS!

Since one of the purposes of this blog is to keep track of bugs for future reference, here was one that caused no end of grief.

1. Some time ago we built an admin tool that used an CFHTTP tag to retrieve a .cfm page and then save the resulting .html to the server. This allowed us to flatten the .cfm pages for serving through Apache. (BTW--This lowered our use of Coldfusion to a minimum and improved our server stability dramatically).
2. Some time later we moved our sites to a new server and had to change DNS to reflect the new IP address of the box.
3. The admin tool was only used sporadically so the next time we used it none of pages would save new content. All of a sudden our admin tool wouldn't work at all!
4. As luck would have it we remembered that we had changed the IP address a week or so before and after some debugging found that CF was still going to the old IP to build the files.
5. Thanks to Google we found some posts that documented that CF caches DNS entries internally so in order to fix the problem you need to restart CF!

Here is one post that explains it (from here):

I just ran across this issue again, CFHTTP requests to a hostname work from one Coldfusion server but not from another. The JVM caches hostname-to-IP address resolution for infinity, by default. This means that if you have a local DNS server with a host name mytest.mydomain.com and it is set to resolve to 127.0.0.1 each CFHTTP request (or CFFTP, CFLDAP, CFINVOKE) to mytest.mydomain.com after the first call will resolve to the IP 127.0.0.1. If you change the DNS entry at some point to resolve to a different IP, Coldfusion never picks up on this change, but instead continues to try and resolve to the old IP address, unless you restart Coldfusion.

You can change the caching policy by editing the networkaddress.cache.ttl value in the cf_root\runtime\jre\lib\security\java.security config file.

No comments: