Revert "OCPBUGS-84534: fix concurrent map race in project authorization cache" - #654
Revert "OCPBUGS-84534: fix concurrent map race in project authorization cache"#654bertinatto wants to merge 1 commit into
Conversation
|
Skipping CI for Draft Pull Request. |
|
@bertinatto: This pull request references Jira Issue OCPBUGS-84534, which is invalid:
Comment The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
WalkthroughAuthorizationCache refactors away atomic pointer-based store swapping in favor of direct store fields, and removes copy-on-write branching from all synchronization paths. Synchronization now always updates subject records in-place. Related benchmarks and race-condition tests are removed. ChangesAuthorizationCache Store and Sync Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/payload-job periodic-ci-openshift-release-main-ci-5.0-e2e-aws-ovn-techpreview |
|
@bertinatto: trigger 3 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command
See details on https://pr-payload-tests.ci.openshift.org/runs/ci/ea3312a0-61d5-11f1-9ac7-7cc707b143ed-0 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/project/auth/cache.go (1)
437-460:⚠️ Potential issue | 🔴 CriticalCritical: cache race from mutating
subjectRecord.namespaceswhileList()iterates + unsafe store swapping
AuthorizationCache.Run()startssynchronize()in a background goroutine, andsynchronize()reuses the livecache.Storeinstances (Lines ~437-455). On the incremental path,deleteNamespaceFromSubjects/addSubjectsToNamespacemutatesubjectRecord.namespacesin place (Lines ~603-624), wherenamespacesis asets.String(map-backed).List()simultaneously reads the same objects and iterates viasubjectRecord.namespaces.List()(Lines ~514-524), which can triggerconcurrent map iteration and map writeand data races. This violates the k8sThreadSafeStorecontract (“you must not modify anything returned by Get or List”; returned pointers are not copied).On full invalidation,
synchronize()also swapsac.userSubjectRecordStore/ac.groupSubjectRecordStore/ac.reviewRecordStorevia plain field assignment (Lines ~458-460) whileList()reads them without synchronization, introducing a separate data race on the store references.Restore copy-on-write/atomic snapshot semantics (clone
subjectRecord/namespaceson updates, and swap snapshots atomically), or guardsynchronize()/List()with shared synchronization so readers never observe concurrently-mutated objects.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/project/auth/cache.go` around lines 437 - 460, The synchronize() path mutates shared subjectRecord.namespaces and swaps store fields unsafely causing concurrent map-iteration and store-reference races; fix by making updates copy-on-write and swapping snapshots atomically: when modifying subjects (in deleteNamespaceFromSubjects and addSubjectsToNamespace) clone the subjectRecord and create a new namespaces sets.String copy before modifying so List() never sees in-place mutations, and for full invalidation (invalidateCache) stop assigning ac.userSubjectRecordStore / ac.groupSubjectRecordStore / ac.reviewRecordStore directly — instead publish the rebuilt stores via a single atomic snapshot (e.g. an atomic.Value or a protected struct) or hold a RWMutex around List() and synchronize() so readers see a consistent snapshot; ensure AuthorizationCache.Run, synchronize(), and List() use the same snapshot mechanism.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@pkg/project/auth/cache.go`:
- Around line 437-460: The synchronize() path mutates shared
subjectRecord.namespaces and swaps store fields unsafely causing concurrent
map-iteration and store-reference races; fix by making updates copy-on-write and
swapping snapshots atomically: when modifying subjects (in
deleteNamespaceFromSubjects and addSubjectsToNamespace) clone the subjectRecord
and create a new namespaces sets.String copy before modifying so List() never
sees in-place mutations, and for full invalidation (invalidateCache) stop
assigning ac.userSubjectRecordStore / ac.groupSubjectRecordStore /
ac.reviewRecordStore directly — instead publish the rebuilt stores via a single
atomic snapshot (e.g. an atomic.Value or a protected struct) or hold a RWMutex
around List() and synchronize() so readers see a consistent snapshot; ensure
AuthorizationCache.Run, synchronize(), and List() use the same snapshot
mechanism.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: f0a7b0f3-b61b-488b-80d2-07329538b8ad
📒 Files selected for processing (2)
pkg/project/auth/cache.gopkg/project/auth/cache_test.go
💤 Files with no reviewable changes (1)
- pkg/project/auth/cache_test.go
|
@bertinatto: This pull request references Jira Issue OCPBUGS-84534. The bug has been updated to no longer refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Reverts #642.
Just checking if this caused failures in TP clusters.
Summary by CodeRabbit
Refactor
Tests