Race Condition Between Filter() and onAddPod() Causes Double Counting - #2484
Race Condition Between Filter() and onAddPod() Causes Double Counting#2484aniket866 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aniket866 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 |
|
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 (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe scheduler adds a reference-counted lock manager keyed by Kubernetes pod UID. It serializes concurrent operations for each UID, removes unused lock entries, ignores unknown unlocks, and includes concurrency and cleanup tests. ChangesPer-pod scheduler locking
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@pkg/scheduler/pod_lock.go`:
- Line 1: Add the repository-standard Apache 2.0 license header before the
package declaration in pkg/scheduler/pod_lock.go (lines 1-1) and
pkg/scheduler/pod_lock_test.go (lines 1-1), leaving the remaining file contents
unchanged.
In `@pkg/scheduler/scheduler_test.go`:
- Around line 2330-2334: Update Scheduler.Bind’s successful Pods(...).Bind path
to call s.releaseAllDevices(node, current) before returning the successful
result. Ensure this release occurs after a successful bind and preserves the
existing error-path behavior so node locks are released before callers proceed
or retry.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8232fac3-6232-46e4-901f-e9c060d990ed
📒 Files selected for processing (4)
pkg/scheduler/pod_lock.gopkg/scheduler/pod_lock_test.gopkg/scheduler/scheduler.gopkg/scheduler/scheduler_test.go
7d49e48 to
08fdfe1
Compare
Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
08fdfe1 to
074b752
Compare
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 1 file with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@aniket866 this Pr is just a duplicate work of #1773 please go through this once. |
|
podlockmanager is never wired into filter() or onaddpod(), scheduler.go is untouched. this does not actually fix the race in #2478, it just adds unused code |
Closes #2478
Race Condition Between Filter() and onAddPod() Causes Double Counting
pkg/scheduler/scheduler.goFilter(), the pod is deleted from the pod manager (line 956), then device usage is recalculated (line 959), then the pod is re-added (line 998). Meanwhile, the pod informer'sonAddPod()(line 138) can fire concurrently and also calls.podManager.AddPod(). Since the PodManager uses UID-based keys, ifonAddPodfires between line 956 and line 998, the pod could be added twice with different device allocations, leading to double-counted resource usage in the quota manager.sequenceDiagram participant Filter as Filter() participant Informer as onAddPod() participant PM as PodManager participant QM as QuotaManager Filter->>PM: TakeAndDeletePod(pod) Note over Filter: Pod removed from cache Informer->>PM: AddPod(pod, nodeID, devices_old) PM-->>Informer: added=true Informer->>QM: AddUsage(pod, devices_old) Filter->>PM: AddPod(pod, nodeID, devices_new) PM-->>Filter: added=false already exists Note over QM: devices_old usage counted but never removed!Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
Tests