Opened 7 years ago

Closed 4 years ago

#4015 defect closed duplicate (duplicate)

names client Resolver class not handling connectionLost

Reported by: pythonologist Owned by:
Priority: normal Milestone:
Component: names Keywords:
Cc: teratorn@…, Richard Wall Branch:


In some circumstances, a twisted.names.client.Resolver instance has the non-existent method connectionLost invoked. Here's a traceback:

Traceback (most recent call last):
  File "", line 724, in run_program
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 1128, in run
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 1140, in mainLoop
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 140, in doSelect
    _logrun(selectable, _drdw, selectable, method, dict)
--- <exception caught here> ---
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\", line 69, in callWithContext
    return{ILogContext: newCtx}, func, *args, **kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\", line 59, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\", line 37, in callWithContext
    return func(*args,**kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 156, in _doReadOrWrite
    self._disconnectSelectable(selectable, why, method=="doRead")
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 190, in _disconnectSelectable
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 509, in readConnectionLost
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 680, in connectionLost
    Connection.connectionLost(self, reason)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\", line 520, in connectionLost
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\names\", line 1769, in connectionLost
exceptions.AttributeError: Resolver instance has no attribute 'connectionLost'

I haven't got a test program as such, just iterate over a variety of domain names. Possibly the DNS server is dropping the connection prior to responding?

Attachments (5)

twisted.names.client.patch (419 bytes) - added by Alrond 7 years ago.
twistd_log.txt (5.0 KB) - added by teratorn 5 years ago.
dig_log.txt (2.5 KB) - added by teratorn 5 years ago.
dig@ (1.3 KB) - added by teratorn 5 years ago.
t.names_to_71.42.153.1.pcap (2.8 KB) - added by teratorn 5 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by Alrond

Resolution: fixed
Status: newclosed

I confirm this problem with the same error output. Temporary may be solved with patch:

--- client.py_original 2009-12-03 15:01:03.000000000 +0100 +++ 2009-12-03 15:01:27.000000000 +0100 @@ -243,6 +243,8 @@

self.queryTCP(q, t).chainDeferred(d)

del self.pending[:]

+ def connectionLost(self, protocol): + pass

def messageReceived(self, message, protocol, address = None):

log.msg("Unexpected message (%d) received from %r" % (, address))

Changed 7 years ago by Alrond

Attachment: twisted.names.client.patch added

comment:2 Changed 7 years ago by Jean-Paul Calderone

Resolution: fixed
Status: closedreopened

The problem actually has to be fixed before the ticket can be closed.

comment:3 Changed 6 years ago by <automation>

Owner: Jean-Paul Calderone deleted

comment:4 Changed 5 years ago by teratorn

Cc: teratorn@… added

I'm hitting this issue, and it seems to be the cause or a symptom of a bug which prevents recursive name lookups from working through a t.names DNS server.

I'm attaching trace files that clearly show the failure. The test scenario is [LAN PC] <--> [GATEWAY PC RUNNING T.NAMES] <--> [ISP DNS SERVER]

LAN PC is; GATEWAY is (internal) and (external); ISP DNS is

Using dig, an A record lookup is performed for, which succeeds. Several minutes are allowed to pass, and then the exception appears in the twistd log file. Then a second A record lookup is performed for, which fails.

Changed 5 years ago by teratorn

Attachment: twistd_log.txt added

Changed 5 years ago by teratorn

Attachment: dig_log.txt added

Changed 5 years ago by teratorn

Attachment: dig@ added

Changed 5 years ago by teratorn

Attachment: t.names_to_71.42.153.1.pcap added

comment:5 Changed 4 years ago by buddyns

The exception here is raised by twisted's Protocol class to the DNSProtocol object used by Names for TCP queries. DNSProtocol deliberately propagates to its controller any connectionLost() call.

The fix of adding a dummy connectionLost() method to Resolver works. An implementation where no empty method is called is more flexible. In names/ :

def connectionLost(self, reason):

... to become:

def connectionLost(self, reason):
    if callable(getattr(self.controller, 'connectionLost')):

comment:6 Changed 4 years ago by Jean-Paul Calderone

#5224 was a duplicate of this.

comment:7 Changed 4 years ago by buddyns

We have been using this solution successfully for a few weeks:

in names/

def connectionLost(self, reason):
    Notify the controller that this protocol is no longer
    if callable(getattr(self.controller, 'connectionLost', None)):

If there's no arguments against, please merge and let's close this ticket.

comment:8 Changed 4 years ago by Richard Wall

Cc: Richard Wall added
Resolution: duplicate
Status: reopenedclosed

Looks like this has already been resolved in #5471 (r33527)

Closing as a duplicate.

Note: See TracTickets for help on using tickets.