Ticket #4015 defect closed duplicate

Opened 5 years ago

Last modified 20 months ago

names client Resolver class not handling connectionLost

Reported by: pythonologist Owned by:
Priority: normal Milestone:
Component: names Keywords:
Cc: teratorn@…, richard@… Branch:
Author: Launchpad Bug:


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 "xmlharness.py", line 724, in run_program
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\base.py", line 1128, in run
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\base.py", line 1140, in mainLoop
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\selectreactor.py", 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\log.py", line 84, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\log.py", line 69, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\python\context.py", 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\context.py", line 37, in callWithContext
    return func(*args,**kw)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\selectreactor.py", line 156, in _doReadOrWrite
    self._disconnectSelectable(selectable, why, method=="doRead")
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\posixbase.py", line 190, in _disconnectSelectable
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\tcp.py", line 509, in readConnectionLost
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\tcp.py", line 680, in connectionLost
    Connection.connectionLost(self, reason)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\tcp.py", line 520, in connectionLost
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\names\dns.py", 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?


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

Change History


Changed 4 years ago by Alrond

  • status changed from new to closed
  • resolution set to fixed

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 +++ client.py 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" % (message.id, address))

Changed 4 years ago by Alrond


Changed 4 years ago by exarkun

  • status changed from closed to reopened
  • resolution fixed deleted

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


Changed 3 years ago by <automation>

  • owner exarkun deleted


Changed 3 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 www.google-analytics.com, 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 www.google-analytics.com, which fails.

Changed 3 years ago by teratorn

Changed 3 years ago by teratorn

Changed 3 years ago by teratorn

Changed 3 years ago by teratorn


Changed 20 months 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/dns.py :

def connectionLost(self, reason):

... to become:

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


Changed 20 months ago by exarkun

#5224 was a duplicate of this.


Changed 20 months ago by buddyns

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

in names/dns.py:

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.


Changed 20 months ago by rwall

  • status changed from reopened to closed
  • cc richard@… added
  • resolution set to duplicate

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

Closing as a duplicate.

Note: See TracTickets for help on using tickets.