fix(ReconnectLDAPObject): reconnect race condition #507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a race condition in ReconnectLDAPObject._apply_method_s() when
multiple threads use a shared ReconnectLDAPObject instance:
While the reconnect() is already protected by
self._reconnect_lock
,there is a small windows between the
unbind_s()
andreconnect()
call, where CPython can switch threads: While the 1st threads is already
waiting inside
reconnect()
for its next try, the 2nd threads will callunbind_s()
outside that lock which will race with the 1st thread alsocalling
unbind_s()
: Whoever comes first will do thedel self._l
first, so the later threads will raise the above AttributeError.
Move calling
unbind_s()
inside the locked region so thatself._l
ishandled atomically.
Add a new parameter
force
to either forcefully close any previousconnection or keep re-use the previous connection if it still is
supposed to work.
PS: This does not fix #253 but addresses https://forge.univention.org/bugzilla/show_bug.cgi?id=43274