@@ -1166,14 +1166,18 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
1166
1166
counter_text ,uri
1167
1167
))
1168
1168
try :
1169
- # Do the connect
1170
- self ._l = ldap .functions ._ldap_function_call (ldap ._ldap_module_lock ,_ldap .initialize ,uri )
1171
- self ._restore_options ()
1172
- # StartTLS extended operation in case this was called before
1173
- if self ._start_tls :
1174
- SimpleLDAPObject .start_tls_s (self )
1175
- # Repeat last simple or SASL bind
1176
- self ._apply_last_bind ()
1169
+ try :
1170
+ # Do the connect
1171
+ self ._l = ldap .functions ._ldap_function_call (ldap ._ldap_module_lock ,_ldap .initialize ,uri )
1172
+ self ._restore_options ()
1173
+ # StartTLS extended operation in case this was called before
1174
+ if self ._start_tls :
1175
+ SimpleLDAPObject .start_tls_s (self )
1176
+ # Repeat last simple or SASL bind
1177
+ self ._apply_last_bind ()
1178
+ except ldap .LDAPError :
1179
+ SimpleLDAPObject .unbind_s (self )
1180
+ raise
1177
1181
except (ldap .SERVER_DOWN ,ldap .TIMEOUT ):
1178
1182
if __debug__ and self ._trace_level >= 1 :
1179
1183
self ._trace_file .write ('*** %s reconnect to %s failed\n ' % (
@@ -1185,7 +1189,6 @@ def reconnect(self,uri,retry_max=1,retry_delay=60.0):
1185
1189
if __debug__ and self ._trace_level >= 1 :
1186
1190
self ._trace_file .write ('=> delay %s...\n ' % (retry_delay ))
1187
1191
time .sleep (retry_delay )
1188
- SimpleLDAPObject .unbind_s (self )
1189
1192
else :
1190
1193
if __debug__ and self ._trace_level >= 1 :
1191
1194
self ._trace_file .write ('*** %s reconnect to %s successful => repeat last operation\n ' % (
0 commit comments