
On 2/27/07, Paul Marks <pmarks@purdue.edu> wrote:
Some users of a program that I'm writing have been reporting this error that I so far have been unable to track down. It seems that it originates from Twisted, but that it skips around my errback handler, and provides no traceback information:
Traceback (most recent call last): Failure: twisted.names.error.DNSQueryTimeoutError:
My query is made from line 121 here: http://dtella.svn.sourceforge.net/viewvc/dtella/tags/1.0.2/dtella_dnslookup.py?revision=406&view=markup
Does anyone have any insight as to where this error could be coming from, and why it isn't getting trapped by my errback function? I don't know yet whether this is a problem in Twisted, or if I'm doing something incorrect in my err_cb.
Update: Yay, I finally found the bug! Turns out it's a problem in Twisted. Inside DNSDatagramProtocol.writeMessage, it writes to the UDP socket, and never checks for socket.error. If a socket.error does occur, then the query() function blows up instead of returning its deferred. So, cancelCall gets forgotten. A few seconds later, it chucks a DNSQueryTimeoutError, and the deferred gets garbage collected without anything handling it. The solution, I think, is this: - in query(), move the "self.writeMessage(m, address)" call up a few lines, to before the Deferred and callLater are created. - Trap socket.error when making this writeMessage call. If it catches one, return a defer.fail() immediately. Basically, if the UDP packet fails to be sent, then the timeout should never be created.