Skip to content

fix: close namespace fd after Setns in joinSandboxNetNs#681

Closed
Atishyy27 wants to merge 1 commit into
urunc-dev:mainfrom
Atishyy27:fix/close-netns-fd-673
Closed

fix: close namespace fd after Setns in joinSandboxNetNs#681
Atishyy27 wants to merge 1 commit into
urunc-dev:mainfrom
Atishyy27:fix/close-netns-fd-673

Conversation

@Atishyy27
Copy link
Copy Markdown

Description

Fixes file descriptor leak in joinSandboxNetNs() by adding defer unix.Close(fd) immediately after opening the namespace file descriptor.

Problem

The function opens a file descriptor to the network namespace but never closes it. Since Kill() returns normally (no exec happens), the O_CLOEXEC flag doesn't help. The fd stays open through the rest of delete --force (Delete() + ExecuteHooks("Poststop")), keeping the namespace reference alive after the VMM is already dead.

Solution

Add defer unix.Close(fd) right after the unix.Open() call and error check. This follows the same pattern used in:

Closing the fd after Setns is safe and won't pull the thread out of the namespace.

Related issues

How was this tested?

Development environment is Windows, so local build/test was not possible (urunc requires Linux syscalls). The fix follows established patterns from vishvananda/netns and runc. CI tests will validate on Linux.

LLM usage

Claude 3.7 Sonnet (via claude.ai) was used to:

  • Analyze the issue and identify the fix
  • Guide through the contribution process
  • Help format the commit message and PR description

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint). (Unable to test on Windows)
  • The e2e tests of at least one tool pass locally. (Unable to test on Windows)
  • If LLMs were used: I have read the llm policy.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 14, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit dd25f51
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6a055ee3dcee2b0008bf86a7

@Atishyy27 Atishyy27 force-pushed the fix/close-netns-fd-673 branch from 85f3514 to cf85484 Compare May 14, 2026 05:11
Fixes urunc-dev#673

Signed-off-by: Atishyy27 <sethatishayjain@gmail.com>
@Atishyy27 Atishyy27 force-pushed the fix/close-netns-fd-673 branch from cf85484 to dd25f51 Compare May 14, 2026 05:34
@cmainas cmainas added invalid This doesn't seem right do-not-merge duplicate This issue or pull request already exists labels May 14, 2026
@cmainas
Copy link
Copy Markdown
Contributor

cmainas commented May 14, 2026

Duplicate with #610 and #634

@Atishyy27
Copy link
Copy Markdown
Author

Closing as duplicate

@Atishyy27 Atishyy27 closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge duplicate This issue or pull request already exists invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Namespace fd not closed after Setns in joinSandboxNetNs

2 participants