Skip to content

Add retry on EINTR. #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Lib/ldap/ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@

from ldap import LDAPError

from errno import EINTR

def _retry_on_interrupted_ldap_call(func, *args, **kwargs):
"""
Call func, retrying if it raises an LDAPError with errno == EINTR.
"""

attempts = 0
while True:
attempts += 1
try:
return func(*args, **kwargs)
except LDAPError as e:
if attempts > 1:
raise e
try:
if 'errno' in e.args[0]:
if e.args[0]['errno'] == EINTR:
time.sleep(0.1)
continue
except IndexError:
pass
raise e

class LDAPBytesWarning(BytesWarning):
"""Python 2 bytes mode warning"""
Expand Down Expand Up @@ -125,7 +148,7 @@ def _ldap_call(self,func,*args,**kwargs):
diagnostic_message_success = None
try:
try:
result = func(*args,**kwargs)
result = _retry_on_interrupted_ldap_call(func,*args,**kwargs)
if __debug__ and self._trace_level>=2:
if func.__name__!="unbind_ext":
diagnostic_message_success = self._l.get_option(ldap.OPT_DIAGNOSTIC_MESSAGE)
Expand Down