HAMi icon indicating copy to clipboard operation
HAMi copied to clipboard

[bug]: Node lock leak when getAllocateResponse fails in NvidiaDevicePlugin.Allocate

Open cotishq opened this issue 4 months ago โ€ข 5 comments

What happened:

In pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go, inside NvidiaDevicePlugin.Allocate(), if plugin.getAllocateResponse() returns an error in the non-MIG allocation path (lines 648โ€“651), the function returns the error immediately without calling PodAllocationFailed(nodename, current, NodeLockNvidia).

Because PodAllocationFailed() is skipped, the node lock (hami.io/mutex.lock) is not released, causing subsequent GPU allocation requests on that node to hang or fail.

What you expected to happen:

When plugin.getAllocateResponse() fails, PodAllocationFailed(nodename, current, NodeLockNvidia) should be invoked to release the node lock before returning the error, consistent with all other error handling paths inside Allocate().

How to reproduce it (as minimally and precisely as possible):

  1. Inspect pkg/device-plugin/nvidiadevice/nvinternal/plugin/server.go lines 648โ€“651
  2. Trigger a failure in getAllocateResponse() (for example, via an invalid CDI specification or configuration).
  3. Observe that the node lock hami.io/mutex.lock is not released upon error return.

Environment:

  • HAMi version: master (https://github.com/Project-HAMi/HAMi/commit/05e6c800b41c5544356682ad5b6bf19d8d6fe838)

cotishq avatar Jul 30 '26 17:07 cotishq

๐Ÿ”— Related PRs

Project-HAMi/HAMi#1989 - Export nvidia device plugin methods for ascend device plugin [merged] Project-HAMi/HAMi#2011 - feat: new mutex GPU scheduling policy [merged] Project-HAMi/HAMi#2043 - fix(device-plugin): avoid nil pointer panic in CheckHealth when checkHealth returns nil [merged] Project-HAMi/HAMi#2054 - fix: skip owner check for legacy lock format [merged] Project-HAMi/HAMi#2087 - feat(device-plugin): support CDI-only NVIDIA accelerators (GB10) [open]


๐Ÿ“ Issue Planner

Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

  • [ ] Create Plan

๐Ÿงช Issue enrichment is currently in open beta.

You can configure auto-planning by selecting labels in the issue_enrichment configuration.

To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

issue_enrichment:
  auto_enrich:
    enabled: false

๐Ÿ’ฌ Have feedback or questions? Drop into our discord!

coderabbitai[bot] avatar Jul 30 '26 17:07 coderabbitai[bot]

@archlitchi, i would love to get your thoughts on this, if confirmed, i can raise a pr to fix it

cotishq avatar Jul 30 '26 17:07 cotishq

@cotishq I don't know whether Kubelet will retry calling Allocate after an error returned. If so, we can't simply release the lock because it will break the assumption that only one Pod is being creating duration the Allocate function.

Shouren avatar Aug 01 '26 18:08 Shouren

@Shouren i dug into the lock implementation more carefully, actually ReleaseNodeLock in pkg/util/nodelock/nodelock.go already has a pod-ownership verification, that checks the annotation owner matches the current pod before releasing, so a retry with different pod would be a safe no-op. on whether kubelet retries - it doesnt in current k8s, Allocate() errors cause immedieate UnexpectedAdmissionError. The actual impact of this missing call is like the lock sits on the node annotation until the TTL expires, blocking all GPU allocations, and all other paths already calls it so this one is the only inconsistent abt it, if this aligns well with you, i would happy to open a pr with the one-line fix .

cotishq avatar Aug 02 '26 15:08 cotishq

@cotishq Since there is no retry mechanism for Pods with UnexpectedAdmissionError, I think it is safe to release the NodeLock.

Shouren avatar Aug 03 '26 09:08 Shouren