cfhttp / JDK caching

Posted by: scoopseven 17 years, 3 months ago

For some reason, cfhttp couldn't connect to our server. We could access it fine from a browser on the machine, which ruled out any firewall blocking on the images.com side. So it looked like ColdFusion was caching the DNS, which wasn't that far from the truth. Turns out the Java JDK just does, NS, not DNS ;) There's a setting in java.security which permanently caches DNS entries that CF uses (cfhttp, cfsmtp, etc.) Instructions for correcting this behavior are from Tom jordahl's bog.
Recently a customer complained about the behavior of CFHTTP in ColdFusion MX: "CFHTTP permanently caches the DNS look-up. This cache can only be flushed by recycling ColdFusion service on the machine in question. Why doesn't CF rely on the server to resolve the domain? What's with caching the DNS look-up at all??" Needless to say, the CFHTTP code doesn't do anything like this because it would make customers mad. :-) So I did a bit of investigation. The underlying library we use to support HTTP operations (after I switched it from using the Java URLConnection class, don't get me started...) uses the Java InetAddress class to look up host names: http://java.sun.com/j2se/1.4.2/docs/api/java/net/InetAddress.html Reading this page you will notice that the JDK caches both positive and negative DNS lookups. And it caches the positive lookups forever. Hey, its not our fault! Luckily, this can be controled by the Java security configuration for the JVM. In JDK 1.4.2 you can edit the file .../lib/security/java.security and set the value networkaddress.cache.ttl, commented out at the bottom of the file, to something other than -1. This controls the time to live for positive DNS results. There are dire security warnings about doing this, but something reasonable, like 4 hours (14,000 seconds), would probably be safe.
**Update - Just install the full Java SDK and point CF (Java and JVM settings) to it to solve this problem. If you end up in a situation where you can't start CF you can update the Java path in CF\runtime\bin\jvm.config.

Currently unrated


Recent Tweets

Recent Posts

Archive

2013
2012
2011
2010
2009
2008
2007
2006

Categories

Authors

Feeds

RSS / Atom