Skip to content

ldap.TIMEOUT unhandled in ReconnectLDAPObject _apply_method_s #446

@xek

Description

@xek

Issue description:

When using ReconnectLDAPObject, if a server disconnects after a connection is created, it fails with an ldap.TIMEOUT which is unhandled.

ldap.TIMEOUT is properly caught only during the initial connection, whereas in _apply_method_s which is applied to synchronous methods, ReconnectLDAPObject only catches the ldap.SERVER_DOWN exception.

Steps to reproduce:

To reproduce the issue, I created the following script to test. I created an interface with the additional 192.168.1.100 address, which I remove after initializing the ReconnectLDAPObject and binding.

import ldap
#from ldappool import StateConnector as Connector
#from ldap.ldapobject import SimpleLDAPObject as Connector
from ldap.ldapobject import ReconnectLDAPObject as Connector
from time import sleep

ldap.set_option(ldap.OPT_NETWORK_TIMEOUT, 10)

c = Connector('ldap://192.168.1.100,ldap://localhost')
c.network_timeout = 10
c.timeout = 10
c.simple_bind_s()
print('sleeping...')
sleep(30) # now remove the 192.168.1.100 IP address from the interface
print('awoke')

result = c.search_s(
    'ou=Users,dc=openstack,dc=org',
    1,
    '(&(objectClass=inetOrgPerson)(uid=*))',
    ['mail', 'userPassword', 'description', 'enabled', 'uid', 'cn'],
    0
)
print(result)
Traceback (most recent call last):                                                               
  File "/home/ubuntu/devstack/test.py", line 18, in <module>                                                                                                                                  
    result = c.search_s(                                
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 631, in search_s                                                                                                     
    return self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout=self.timeout)
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 1030, in search_ext_s                                                                                                
    return self._apply_method_s(SimpleLDAPObject.search_ext_s,*args,**kwargs)            
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 968, in _apply_method_s                                                                                              
    return func(self,*args,**kwargs)                                                             
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 625, in search_ext_s
    return self.result(msgid,all=1,timeout=timeout)[1]                                           
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 535, in result                                                                                                       
    resp_type, resp_data, resp_msgid = self.result2(msgid,all,timeout)                       
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 539, in result2         
    resp_type, resp_data, resp_msgid, resp_ctrls = self.result3(msgid,all,timeout)     
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 543, in result3
    resp_type, resp_data, resp_msgid, decoded_resp_ctrls, retoid, retval = self.result4(
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 553, in result4
    ldap_result = self._ldap_call(self._l.result4,msgid,all,timeout,add_ctrls,add_intermediates,add_extop)
  File "/usr/local/lib/python3.9/dist-packages/ldap/ldapobject.py", line 128, in _ldap_call
    result = func(*args,**kwargs)                                                                
ldap.TIMEOUT                

Operating system:

GNU Linux Ubuntu 21.04

Python version:

Python 3.9.5

python-ldap version:

3.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions