RANGER-5678: Concurrent policy-engine rebuild on shared serviceDef causes CME/NPE for delegated-admin User - #1112
Open
vyommani wants to merge 1 commit into
Open
RANGER-5678: Concurrent policy-engine rebuild on shared serviceDef causes CME/NPE for delegated-admin User#1112vyommani wants to merge 1 commit into
vyommani wants to merge 1 commit into
Conversation
…uses CME/NPE for delegated-admin User
Contributor
Author
|
@mneethiraj , @pradeepagrawal8184 , can you please review this PR when you get time. |
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 changes were proposed in this pull request?
Under concurrent delegated-admin V2 API load, multiple threads rebuild the policy engine for the same service — or for services that share a tag serviceDef — at the same time. Each rebuild calls ServiceDefUtil.normalize() on the shared, cached RangerServiceDef, which mutates it in place, causing ConcurrentModificationException/NullPointerException under concurrent access.
The fix makes ServiceDefUtil.normalize() return a deep copy of the RangerServiceDef instead of mutating its input.
Initially, I assumed adding copy constructors and changing normalize() to copy-then-mutate would be enough on its own. However, ServiceDefUtil.normalize() was both mutating its input and returning it — which made its original intent ambiguous: was the return value meant to be authoritative, or was it just a convenience alongside the real effect (the in-place mutation)? Rather than guess, I took the conservative approach: treat the return value as authoritative, and update every call site to propagate the returned (now-copied) RangerServiceDef back to wherever the caller had originally expected the mutation to be visible. This keeps the change behavior-preserving — nothing that depended on seeing the normalized state after calling normalize() loses that guarantee — while fully resolving the CME/NPE.
How was this patch tested?
Existing unit tests updated and passing.
New test testNormalizeDoesNotMutateOrShareStateWithSource verifies identity and content isolation.
Local concurrency exercises (same serviceDef + cross-service shared tag serviceDef) no longer reproduce the CME/NPE