Merger tolerates backend disconnect (fixes #231) - #260
Merged
Conversation
Two related pathologies fixed:
1. _clientQueue used to blindly iterate self.clients and call
send_multiResponse, which raised LDAPClientConnectionLostException
if a backend had already lost its connection. Now we skip
disconnected clients and swallow the race between .connected and
.send raising.
2. queue() sized its response Queue to len(self.clients) at
first-response time, so a backend that never responded would hang
the search forever. Replaced with an {expected, responses} dict
whose expected count is decremented both on each arriving response
and on each backend disconnect. When expected drops to zero the
accumulated best response is forwarded; if no backend answered at
all, a synthetic LDAPOther is returned.
_cbConnectionMade now hooks each backend's notifyOnDisconnect (from
batch 5) to prune it from self.clients and nudge every outstanding
merge. LDAPClientTestDriver in testutil grew a matching
notifyOnDisconnect so tests can exercise the disconnect path.
Regression test in test_merger covers the "one of two backends dies
before the search is dispatched" case. Full suite green on
py3.11 / 3.13 / 3.14.
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #260 +/- ##
==========================================
+ Coverage 83.49% 83.52% +0.03%
==========================================
Files 87 87
Lines 11666 11748 +82
Branches 1004 1012 +8
==========================================
+ Hits 9740 9812 +72
- Misses 1815 1821 +6
- Partials 111 115 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Codecov flagged patch coverage at 78.57% on #260 (12 lines missed). Add three focused tests: * mid-flight death: seed a merge with one Done, then disconnect the peer; the decrement-and-check loop finishes the merge with the survivor's response. * all backends die: seed an empty merge, drop both backends; the synthetic LDAPOther is emitted. * defensive-paths sweep: _cbClientLost on an already-pruned proto, _checkComplete on an unknown id, _clientQueue skipping a client whose connected flag was flipped without notifyOnDisconnect firing, and _clientQueue swallowing LDAPClientConnectionLostException. merger.py patch coverage is now 100% (module 85% -> 91%; remaining holes are pre-existing: _failConnection, the TLS branch, the dead assert, and the __main__ demo).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Merger tolerates backend disconnect (fixes #231)
Two related pathologies fixed:
_clientQueue used to blindly iterate self.clients and call send_multiResponse, which raised LDAPClientConnectionLostException if a backend had already lost its connection. Now we skip disconnected clients and swallow the race between .connected and .send raising.
queue() sized its response Queue to len(self.clients) at first-response time, so a backend that never responded would hang the search forever. Replaced with an {expected, responses} dict whose expected count is decremented both on each arriving response and on each backend disconnect. When expected drops to zero the accumulated best response is forwarded; if no backend answered at all, a synthetic LDAPOther is returned.
_cbConnectionMade now hooks each backend's notifyOnDisconnect (from batch 5) to prune it from self.clients and nudge every outstanding merge. LDAPClientTestDriver in testutil grew a matching notifyOnDisconnect so tests can exercise the disconnect path.
Regression test in test_merger covers the "one of two backends dies before the search is dispatched" case. Full suite green on py3.11 / 3.13 / 3.14.