Skip to content

Comments

Unshare the FD table when creating threads in init to avoid fd leaks#14231

Merged
OneBlue merged 6 commits intofeature/wsl-for-appsfrom
user/oneblue/unshare-hang
Feb 24, 2026
Merged

Unshare the FD table when creating threads in init to avoid fd leaks#14231
OneBlue merged 6 commits intofeature/wsl-for-appsfrom
user/oneblue/unshare-hang

Conversation

@OneBlue
Copy link
Collaborator

@OneBlue OneBlue commented Feb 19, 2026

Summary of the Pull Request

This change solves a potential FD leak that can happen if multiple WSLA shells are open at the same time.

The leak happens when threads inside of init create children processes, which inherit all fd from their parents by default. If that happens while an hvsocket is opened, that socket is inherited in the child, which will never close it, causing a hang

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@OneBlue OneBlue requested a review from a team as a code owner February 19, 2026 00:40
Copilot AI review requested due to automatic review settings February 19, 2026 00:40
Copy link
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 prevent file-descriptor inheritance/leaks when WSLA init creates “thread” fork handlers, by detaching the thread’s file-descriptor table so other init threads’ child processes don’t inherit hvsockets opened by the handler thread.

Changes:

  • Add unshare(CLONE_FILES) when handling WSLA_FORK::Thread in WSLAInit.cpp to detach the thread’s FD table and reduce FD inheritance.

}

// ListenSocket should only be assigned after this thread is guaranteed to have its own fd table (either via unshare() or a child process).
ListenSocket.reset(ListenSocketFd);
Copy link
Member

Choose a reason for hiding this comment

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

This doesn’t seem right to me. Both this thread and the parent have this file descriptor.

Copy link
Member

Choose a reason for hiding this comment

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

I believe this is correct since the file descriptor here is in a separate table from the parent.

Copy link
Member

Choose a reason for hiding this comment

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

yeah I couldn't quite follow the logic, this seems right to me.

@OneBlue OneBlue merged commit b072808 into feature/wsl-for-apps Feb 24, 2026
6 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