Make VMPortMapping::Unmap idempotent#40091
Merged
benhillis merged 2 commits intofeature/wsl-for-appsfrom Apr 6, 2026
Merged
Conversation
Null out Vm after unmapping so a second call is a no-op. This prevents double-unmap errors when ReleaseRuntimeResources is called from both OnEvent(Stop) and a concurrent Delete(Force) path.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make VMPortMapping::Unmap() safe to call multiple times during container/runtime cleanup by ensuring an already-unmapped port relay doesn’t cause repeated failures.
Changes:
- Update
VMPortMapping::Unmap()to null outVmafter callingUnmapPort().
Use a scope_exit to null Vm so that Unmap() is truly idempotent even when UnmapPort() throws. Previously Vm stayed non-null on the failure path, causing subsequent Unmap() calls to retry and throw again. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
beena352
approved these changes
Apr 3, 2026
OneBlue
approved these changes
Apr 3, 2026
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.
Null out Vm after UnmapPort() so a second call to Unmap() is a no-op.
This matches the pattern already used by UnmountVolumes (which checks volume.Mounted). Without this, if ReleaseRuntimeResources is called twice (e.g. from OnEvent(Stop) and a concurrent Delete(Force) path), UnmapPort would be called on an already-unmapped relay.