-
Notifications
You must be signed in to change notification settings - Fork 126
Reconnect also on ldap.UNAVAILABLE #267
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
base: main
Are you sure you want to change the base?
Conversation
The same applies to |
Codecov Report
@@ Coverage Diff @@
## master #267 +/- ##
======================================
Coverage 71.1% 71.1%
======================================
Files 49 49
Lines 4818 4818
Branches 812 812
======================================
Hits 3426 3426
- Misses 1056 1057 +1
+ Partials 336 335 -1
Continue to review full report at Codecov.
|
Also |
I adjusted the Pull Request so that one can specify which exceptions should be catched for reconnecting. Therefore it would be extensible and if you want backwards compatibility. If you plan to merge this tell me, I would squash the first and second commit. |
We need this until python-ldap/python-ldap#267 is fixed
We need this until python-ldap/python-ldap#267 is fixed
We need this until python-ldap/python-ldap#267 is fixed
There is another issue, which is triggered, when re-using a connection after a import ldap
import subprocess
lo = ldap.ldapobject.ReconnectLDAPObject(uri)
dn = lo.whoami_s()[3:]
# stop open ldap
subprocess.call(['service', 'slapd', 'stop'])
# do a search, wait for the timeout, handle SERVER_DOWN exception
try:
print(lo.search_s(dn, ldap.SCOPE_BASE, '(objectClass=*)'))
except ldap.SERVER_DOWN:
pass # some handling here
# start open ldap again
subprocess.call(['service', 'slapd', 'start'])
# try to use the connection again
print(lo.search_s(dn, ldap.SCOPE_BASE, '(objectClass=*)'))
# this now raises ldap.INSUFFICIENT_ACCESS, as it is now a unbound connection and does everything anonymously. |
Is it possible to test this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please rebase your PR and provide tests and documentation updates (.. versionadded:: 3.3
)?
e214b39
to
00e7186
Compare
@tiran Ok, I implemented the 2 new test cases. I would revert making And then I would revert the changes once so that we see that TravisCI actually really fails with the new test cases. |
00e7186
to
8a5db63
Compare
@tiran ping. |
Yes, I have some reservations to handling Not sure what to do when the first server in the list is contactable but broken (TLS, ...), libldap might not take that as a clue to try the next one so we'd need to shuffle the URI list manually? Regarding the test cases, can't see how they're going to fail, especially the threaded one? |
The exceptions come from real-life customer environments where they occurred. |
Please describe a situation where python-ldap has enough information to retry
The point is that |
I can't explain
But the test will fail if you drop the exception handling. |
That wasn't my question, if you get a TIMELIMIT_EXCEEDED, how do you know this is because a server is down and retrying will pick up a different one? With an overloaded/misconfigured server, the retry will fail the same and the application still needs to be ready to do whatever is needed to reconsider/retry, including shuffling the URI list. I don't object to making the exception list configurable, however spaghetti this code looks already (using something like python-tenacity would have been much better). Then it's up to the application to decide what kinds of errors are safe to retry from automatically and which ones would need to be handled by the caller.
Oh you get a lot of tracebacks printed out, I can see that, but my point is the test passes anyway. |
8a5db63
to
12994f2
Compare
@mistotebe ah OK, now I get you. Adding a dependency on https://github.com/jd/tenacity is probably not a good idea now. I like that pyhton-ldap has few dependencies. I reworked the tests so that the failing condition is explicit - I thought a failing thread would propagate the error, sorry for that. |
I'll try to fix some of the failing tests |
3acbfdd
to
412a35d
Compare
can the tests be run again? the logs aren't available anymore, I'd still be interested in a fix (I'm the "ghost user" above). |
any update on this? this blocks https://bugs.launchpad.net/keystone/+bug/1953627 |
@spaceone hi! Could you please rebase the commit in this PR? (and possibly check out the above questions), and we'll rerun the tests. |
48edd06
to
b222122
Compare
96c08b9
to
6d22640
Compare
@mistotebe @tiran ping. anything else? |
It is good from my side, @tiran you are marked as "requested changes", could you review again and adjust if appropriate? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now
6d22640
to
45c3975
Compare
This comment was marked as outdated.
This comment was marked as outdated.
test_106_reconnect_restore() handles a SERVER_DOWN exception manually and tries to re-use the connection afterwards again. This established the connection again but did not bind(), so it now raises ldap.INSUFFICIENT_ACCESS. test_107_reconnect_restore() restarts the LDAP server during searches, which causes a UNAVAILABLE exception.
45c3975
to
3e9320a
Compare
OK, the tests have been refactored and run:
|
LDAP connections may also raise
UNAVAILABLE
not onlySERVER_DOWN
. It would be nice if the reconnection class also reconnects in this case.Below is an example script which can provoke the scenario: