Opened 5 years ago

Closed 2 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@… Branch:
Author: Launchpad Bug:

Description

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
    reactor.run()
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\base.py", line 1128, in run
    self.mainLoop()
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\base.py", line 1140, in mainLoop
    self.doIteration(t)
  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
    selectable.readConnectionLost(f)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\internet\tcp.py", line 509, in readConnectionLost
    self.connectionLost(reason)
  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
    protocol.connectionLost(reason)
  File "C:\software\python26\lib\site-packages\twisted-8.2.0\twisted\names\dns.py", line 1769, in connectionLost
    self.controller.connectionLost(self)
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 5 years ago.
twistd_log.txt (5.0 KB) - added by teratorn 3 years ago.
dig_log.txt (2.5 KB) - added by teratorn 3 years ago.
dig@10.0.0.1.pcap (1.3 KB) - added by teratorn 3 years ago.
t.names_to_71.42.153.1.pcap (2.8 KB) - added by teratorn 3 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 5 years ago by Alrond

  • Resolution set to fixed
  • Status changed from new to closed

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 5 years ago by Alrond

comment:2 Changed 5 years ago by exarkun

  • Resolution fixed deleted
  • Status changed from closed to reopened

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

comment:3 Changed 4 years ago by <automation>

  • Owner exarkun deleted

comment:4 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 10.0.0.222; GATEWAY is 10.0.0.1 (internal) and 71.42.153.210 (external); ISP DNS is 71.42.153.1

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

comment:5 Changed 2 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/dns.py :

def connectionLost(self, reason):
    self.controller.connectionLost(self)

... to become:

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

comment:6 Changed 2 years ago by exarkun

#5224 was a duplicate of this.

comment:7 Changed 2 years 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
    connected.
    """
    if callable(getattr(self.controller, 'connectionLost', None)):
        self.controller.connectionLost(self)

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

comment:8 Changed 2 years ago by rwall

  • Cc richard@… added
  • Resolution set to duplicate
  • Status changed from reopened to closed

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

Closing as a duplicate.

Note: See TracTickets for help on using tickets.