fix(device-plugin): guard Allocate() against empty DevicesIds to prevent process-crashing panic - #2406
Conversation
…ent process-crashing panic Signed-off-by: AyushSrivastava1818 <ayush.sri0705@gmail.com>
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesAllocation validation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
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.
🧹 Nitpick comments (1)
pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go (1)
1443-1455: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the allocation contract for each table case.
The successful cases pass when
Allocatereturns an emptyContainerResponsesslice. Assert the expected response count and allocated device identifiers for both MIG and non-MIG cases.The empty request case only checks
"has no DevicesIds". Assert"container request 0"so the test preserves the indexed validation-error contract.🤖 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/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go` around lines 1443 - 1455, The Allocate table tests currently verify only response presence and errors, not allocation contents. Extend the success assertions around plugin.Allocate to check the expected ContainerResponses count and allocated device identifiers for both MIG and non-MIG cases, using the table case expectations. Strengthen the empty-request error assertion to require the indexed “container request 0” text in addition to “has no DevicesIds”.
🤖 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.
Nitpick comments:
In `@pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go`:
- Around line 1443-1455: The Allocate table tests currently verify only response
presence and errors, not allocation contents. Extend the success assertions
around plugin.Allocate to check the expected ContainerResponses count and
allocated device identifiers for both MIG and non-MIG cases, using the table
case expectations. Strengthen the empty-request error assertion to require the
indexed “container request 0” text in addition to “has no DevicesIds”.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c02bb31-743e-4288-a68d-ab1c1fffed84
📒 Files selected for processing (2)
pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.gopkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
please resolve this conflicts |
|
/assign |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: AyushSrivastava1818 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 |
|
@archlitchi resolved the conflicts take a look whenever you are free! |
|
Thanks for considering defensive handling here. No supported kubelet path or production reproduction reaching an Allocate request with an empty DevicesIds list has been shown; the supplied reproduction requires sending a malformed gRPC request directly. The current PR adds a large test harness for a very small guard and is already conflicting with master. The maintenance cost is not justified by the available evidence, so we are closing this PR. A new change would need a real kubelet/runtime reproduction or a confirmed protocol requirement. |
Summary
In
pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go,Allocate()iterates overreqs.ContainerRequestsand accessesreq.DevicesIds[0]without checking ifDevicesIdsis empty. If a request with an emptyDevicesIdsslice is received, Go panics withruntime error: index out of range [0]. Because the gRPC server has no panic-recovery interceptor, this crashes the entirenvidia-device-pluginprocess — affecting every pod on the node waiting on GPU allocation, not just the one triggering the bad request.This PR adds a guard at the top of the
ContainerRequestsloop:PodAllocationFailed(nodename, current, NodeLockNvidia)to clean up node locks and pod status annotations.nil, fmt.Errorf("invalid allocation request: container request %d has no DevicesIds", idx)for a clean gRPC error instead of a crash.Fixes #2405
Changes
pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go: addlen(req.DevicesIds) == 0check beforereq.DevicesIds[0]is accessed.pkg/device-plugin/nvidiadevice/nvinternal/plugin/server_test.go: add table-driven unit testTestAllocate_EmptyDevicesIdsAndRegressioncovering:DevicesIds→ non-nil error, no panic,PodAllocationFailedinvoked (asserted directly, not just the error return).Test Matrix & Verification Status
go testandmake verifycannot compilepkg/device-plugin/nvidiadevice/nvinternal/pluginlocally due to pre-existing CGo / Linux-only dependencies (go-nvml,nvidia-container-toolkit,opencontainers/cgroupsusingsyscall.Mmap/unix.Mkdev). This occurs identically on an unmodifiedmastercheckout.go test, andmake verifywill run on Linux runners.AI Assistance Disclosure
I used AI assistance (Claude) to identify this panic risk, implement the guard, and draft the regression test. I reviewed the diff, ran the test suite where locally possible, and take full responsibility for the final change.
Summary by CodeRabbit
Bug Fixes
Tests