June 19, 2003

dns woes

it's time for mozilla's dns implementation to be rewritten... no, i'm not talking about a real DNS resolver implementation. we just call gethostbyname (or one of the re-entrant IPv6 friendly flavors), really! but...

the current codebase is really showing its age. it's a fragile piece of multithreaded crap that suffers from layers-upon-layers of patches and an interface that is everything one should avoid when creating an xpcom interface.

with drastically different implementations for windows, mac classic, and other, maintenance is a complete headache. what we need (and what we can really easily achieve) is a single, cross-platform solution. microsoft kindly showed us the way by only supporting IPv6 via the new getaddrinfo API... who uses IPv4-mapped-IPv6 addresses anyways?!? :-/

so, the plan is to whittle the code down to a single implementation that calls getaddrinfo when supported by the host platform and gethostbyname (or whatever re-entrant flavor is available) otherwise.

the other big nasty with the DNS code is shutdown. a function like getaddrinfo or gethostbyname may block the calling thread seemingly forever, prompting the three-finger-salute. we have this problem today under linux and osx.

the solution, i think, is to spin up multiple detached (or unjoinable) background threads. each thread will call getaddrinfo and then communicate the result back to the resolver, which may hand the result off to several listeners. at shutdown, we will not wait for these threads to exit. the resources these threads access after getaddrinfo returns will be reference counted on the number of DNS threads plus one. this ensures that the background threads won't run into corrupted memory if the main thread has already shutdown. of course, on windows and some other platforms all background threads are abruptly terminated when the main thread exits. under linux, this is not the case, so we have to be careful. the only real problem with this solution is that tools like purify are likely to bitch. oh well :-/

finally, there is the issue of DNS caching. mozilla likes to cache IP addresses for the entire browser session in a hackish attempt to defeat a specific security threat. this makes many people unhappy, and generally causes lot's of unexpected and undesirable side-effects. we need to back off on this solution and come up with something smarter. what that is exactly remains to be determined... but, in the near term it probably involves a pref and a user prompt :-(

Posted by darin at 12:25 AM | Comments (22)