fix: LiveQuery role cache is not invalidated for all users affected by a role write or delete - #10629
Conversation
…y a role write or delete
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughLiveQuery role changes now publish invalidation messages without requiring an acting user. Messages can request full authorization and role-cache clearing, while legacy messages retain targeted invalidation. Tests cover both paths and cache-clear failures. ChangesLiveQuery role-cache invalidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Mergeability Score: ⚪ Minimal · up to This change is merge-ready after normal checks and review; no actionable merge-blocking risk remains. Sequence Diagram(s)sequenceDiagram
participant LiveQueryController
participant ParseCloudCodePublisher
participant ParseLiveQueryServer
participant CacheController
LiveQueryController->>ParseCloudCodePublisher: publish role-cache invalidation
ParseCloudCodePublisher->>ParseLiveQueryServer: send clearAll and optional userId
ParseLiveQueryServer->>CacheController: clear authentication and role caches
CacheController-->>ParseLiveQueryServer: complete or reject role-cache clearing
Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Pull Request
Issue
Closes #10628.
LiveQueryController.clearCachedRoles(user)invalidated the LiveQuery server's cached auth for one user, the actor on the request, and only when there was one. Two cases were never invalidated:userwas falsy, so a master key role write or delete published nothing at all. Managing roles with the master key, from admin tooling or cloud code, is the common case.{ userId }andParseLiveQueryServer#_clearCachedRolesresolved_Sessionrows for that one user. A role write changes the effective closure of every member of the role and of any role inheriting from it. Adding a member is the clearest example: the actor is the admin doing the write, the affected user is the member being added, and only the actor was invalidated.Until its
authCacheentry expired oncacheTimeout, a subscriber kept receiving events decided from a stale role closure.Approach
clearCachemessages now carryclearAll: true, and a LiveQuery server receiving one drops its wholeauthCacherather than one user's sessions. Entries are repopulated lazily bygetAuthForSessionToken, so the cost is a re-resolution per active session after a role write, and role writes are rare relative to events.Three details worth reviewer attention:
userIdis still published when it is known. A LiveQuery server on an older version ignoresclearAlland readsuserId, so it keeps doing exactly what it does today rather than silently doing nothing. Mixed-version deployments degrade to current behavior instead of breaking._clearCachedRoles(userId)is kept for the reverse direction, an older Parse Server publishing{ userId }to a LiveQuery server on this version.cacheController.role.clear()never touched. Failures there are caught and logged rather than propagated, matching_clearCachedRoles.The whole cache is cleared rather than a computed set of affected sessions because the affected set cannot be reconstructed for a delete: by the time the message is published, the
_Rolerow and its_Joinrows are gone. Snapshotting members before the destroy would put the cost on every delete and still miss transitive members.Tests
spec/ParseLiveQueryServer.spec.jsgains arole cache invalidationblock:clearAll, which is the master key case that previously published nothing.userIdalongsideclearAll, pinning the back compat contract.clearAllmessage routes to the full clear, and a message without it routes to the targeted clear.authCacheand clears the role cache.spec/ParseLiveQueryServer.spec.js,spec/ParseLiveQuery.spec.js,spec/ParseRole.spec.js,spec/Auth.spec.jsandspec/rest.spec.jsall pass against MongoDB 8.Tasks
Summary by CodeRabbit