[Twisted-Python] Ldaptor: [PATCH] Reroute errback to deferred returned by search()

Anton Gyllenberg anton at iki.fi
Wed Sep 1 07:52:06 EDT 2010

The LDAPEntryWithClient.search() method used to send the LDAP request with
a call like
	self.client.send_multiResponse(... )
send_multiResponse() returns a deferred that was just discarded. If the
operation causes an error then the errback fired on the discarded deferred
will remain unhandled. The deferred returned by search() will then not
have any errback fired and the caller of search() will be waiting forever.

This change adds an errback to the deferred returned by send_multiResponse()
and has the error rerouted to the errback chain of the deferred returned by

Discussion: This hits right into the internals of Ldaptor and I am not
sure I understand this well enough to make an accurate fix. The
problem I encountered is real and can be reproduced, and this change
does seem to work around it.

Any comments and suggestions welcome!

 ldaptor/protocols/ldap/ldapsyntax.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/ldaptor/protocols/ldap/ldapsyntax.py
index f54d2f8..471ffa6 100644
--- a/ldaptor/protocols/ldap/ldapsyntax.py
+++ b/ldaptor/protocols/ldap/ldapsyntax.py
@@ -683,7 +683,7 @@ class LDAPEntryWithClient(entry.EditableLDAPEntry):
-            self.client.send_multiResponse(
+            dsend = self.client.send_multiResponse(
                 op, self._cbSearchMsg,
                 d, cb, complete=not attributes,
@@ -692,6 +692,11 @@ class LDAPEntryWithClient(entry.EditableLDAPEntry):
             if callback is None:
                 d.addCallback(lambda dummy: results)
+            def rerouteerr(e):
+                d.errback(e)
+                # returning None will stop the error
+                # from being propagated and logged.
+            dsend.addErrback(rerouteerr)
         return d

     def lookup(self, dn):

More information about the Twisted-Python mailing list