Caching behaviour of InetAddress

Alan Bateman Alan.Bateman at Sun.COM
Mon Feb 18 02:17:11 PST 2008


Andreas Plesner Jacobsen wrote:
> I've recently been introduced to the caching behaviour of InetAddress, 
> and I think it may be improved.
>
> The javadoc reads:
> The InetAddress class has a cache to store successful as well as 
> unsuccessful host name resolutions. The positive caching is there to 
> guard against DNS spoofing attacks; while the negative caching is used 
> to improve performance.
>
> And that is all fine and well, but for multihomed hosts, I believe the 
> current behaviour is
>
> 1) Not documented properly
> 2) Not correct
>
> Coming from a unix-world, I'm used to the resolver handing out 
> RR-replies in random order, and thus I would expect InetAddress to do 
> the same, 
The specification could be improved but changing InetAddress.getByName 
to return a random address is a significant change that could break 
existing applications. It might be better to define a new method, 
perhaps "getAnyByName", that randomly chooses one of the cached 
addresses for the host (or does a lookup if not in the cache). That 
would be a convenience to applications to avoid needing to invoke 
getAllByName and choose an address themselves.

-Alan.



More information about the net-dev mailing list