fix(policy): release pr.mu during executeEvictWhere peer evaluation (PILOT-104)#3
Merged
Merged
Conversation
…PILOT-104) executeEvictWhere previously held pr.mu (exclusive write lock) while iterating over every peer and calling EvaluatePeerExpr for each one. Each peer expression evaluation has a 100 ms timeout. With 1 000 peers worst-case the lock was held for ~100 seconds, blocking reconcileMembership, applyMembershipDiff, and every other mu-requiring path in the daemon-side policy engine. Fix: snapshot peer pointers under pr.mu.RLock(), release, evaluate policies outside the lock, then re-acquire pr.mu.Lock() briefly to apply evictions. Concurrent peer removals between the snapshot and re-acquire are harmless — delete on a non-existent map key is a no-op. The write-critical section is now O(1) regardless of peer count. Closes PILOT-104
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
Status:
|
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.
What failed
executeEvictWhereheldpr.mu(exclusive write lock) while iterating over every peer and callingEvaluatePeerExprfor each one. Each peer expression evaluation has a 100 ms timeout (policylang/engine.go:246). With 1 000 peers worst-case the lock was held for ~100 seconds, blockingreconcileMembership,applyMembershipDiff, and every other mu-requiring path in the daemon-side policy engine.Why this fix
Snapshot peer pointers under
pr.mu.RLock(), release, evaluate policies outside the lock, then re-acquirepr.mu.Lock()briefly to apply evictions. Concurrent peer removals between the snapshot and re-acquire are harmless —deleteon a non-existent map key is a no-op.The write-critical section is now O(1) regardless of peer count.
Verification
go build ./...— cleango vet ./...— cleango test ./...— all green (policy + policylang, 5.5s suite)TestPin_LargePeerList_EvictWhereBoundedLatency(5k peers) passesChanges
runner.go:executeEvictWhere— +19/-7 lines (snapshot + split lock pattern)Closes PILOT-104