Skip to content

Make VMPortMapping::Unmap idempotent#40091

Merged
benhillis merged 2 commits intofeature/wsl-for-appsfrom
user/benhill/review_idempotent-unmap
Apr 6, 2026
Merged

Make VMPortMapping::Unmap idempotent#40091
benhillis merged 2 commits intofeature/wsl-for-appsfrom
user/benhill/review_idempotent-unmap

Conversation

@benhillis
Copy link
Copy Markdown
Member

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.

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.
@benhillis benhillis requested a review from a team as a code owner April 3, 2026 05:10
Copilot AI review requested due to automatic review settings April 3, 2026 05:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 out Vm after calling UnmapPort().

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>
@benhillis benhillis merged commit dbfe96f into feature/wsl-for-apps Apr 6, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants