[shim] Fix GPU ownership of restored tasks - #4218
Merged
Merged
Conversation
restoreStateFromContainers() stored the GPU IDs extracted from the container on the task, but GpuLock.Lock() locks only the GPUs that are not locked yet and returns that subset. If two restored containers report the same GPU, the second task claims a GPU it does not hold, and releasing that task's resources frees a GPU the first one is still using. A restored task now owns only the GPUs actually locked for it. The GPUs locked for a task that cannot be stored, e.g., one with a duplicate task ID, are released as well, as nothing else will release them. Also adds the first tests covering restoreStateFromContainers(). They use a fake docker.APIClient implementing the two methods it calls, so they need no Docker daemon. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
restoreStateFromContainers() stored the GPU IDs extracted from the container on the task, but GpuLock.Lock() locks only the GPUs that are not locked yet and returns that subset. If two restored containers report the same GPU, the second task claims a GPU it does not hold, and releasing that task's resources frees a GPU the first one is still using.
A restored task now owns only the GPUs actually locked for it. The GPUs locked for a task that cannot be stored, e.g., one with a duplicate task ID, are released as well, as nothing else will release them.
Also adds the first tests covering restoreStateFromContainers(). They use a fake docker.APIClient implementing the two methods it calls, so they need no Docker daemon.