Hi all,
I'm trying to use dnspython in a threaded CherryPy app, but as far as
I can tell the Resolver class is not threadsafe. I create 1 Resolver
instance per thread and when I do a number of lookups across all
threads I get a number of exceptions like this one:
Exception in thread Thread-29:
Traceback (most recent call last):
File "threading.py", line 460, in __bootstrap
self.run()
File "threading.py", line 440, in run
self.__target(*self.__args, **self.__kwargs)
File "testing/dnsutil_thread_tester.py", line 31, in worker
host = resolver.reverse(ip)
File "/home/.../G/bix/ui/bixui/lib/dnsutil.py", line 19, in reverse
response = self.resolver.query(q, 'PTR')
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/resolver.py",
line 590, in query
request = dns.message.make_query(qname, rdtype, rdclass)
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/message.py",
line 1032, in make_query
m = Message()
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/message.py",
line 137, in __init__
self.id = dns.entropy.random_16()
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/entropy.py",
line 92, in random_16
return pool.random_16()
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/entropy.py",
line 69, in random_16
return self.random_8() * 256 + self.random_8()
File
"/home/.../lib/python2.5/site-packages/dnspython-1.7.1-py2.5.egg/dns/entropy.py",
line 64, in random_8
value = ord(self.digest[self.next_byte])
IndexError: string index out of range
I'm guessing the problem is caused by the global EntropyPool object at
the bottom of the entrop.py file.
I really have no idea what the purpose of the dns.entropy module is,
but it appears to be doing far too much work just to generate random
numbers. os.urandom(n) seems like a fine replacement for the mix of
random_n() functions (where n is 8, 16, and 32).
Furthermore there are a number of catch-all except statements and
using file('...') as opposed to open('...').
There may be other thread safety issues with dnspython, but this
entire module seems in dire need of a simpler replacement. I don't
have git handy, but I may try to work up a patch. :-)
Thanks,
Michael Schurter
@schmichael
_______________________________________________
dnspython-users mailing list
[email protected]
http://howl.play-bow.org/mailman/listinfo.cgi/dnspython-users