Unshare the FD table when creating threads in init to avoid fd leaks#14231
Merged
OneBlue merged 6 commits intofeature/wsl-for-appsfrom Feb 24, 2026
Merged
Unshare the FD table when creating threads in init to avoid fd leaks#14231OneBlue merged 6 commits intofeature/wsl-for-appsfrom
OneBlue merged 6 commits intofeature/wsl-for-appsfrom
Conversation
Contributor
There was a problem hiding this comment.
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 handlingWSLA_FORK::ThreadinWSLAInit.cppto detach the thread’s FD table and reduce FD inheritance.
ptrivedi
reviewed
Feb 20, 2026
johnstep
reviewed
Feb 21, 2026
benhillis
reviewed
Feb 24, 2026
| } | ||
|
|
||
| // 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); |
Member
There was a problem hiding this comment.
This doesn’t seem right to me. Both this thread and the parent have this file descriptor.
Member
There was a problem hiding this comment.
I believe this is correct since the file descriptor here is in a separate table from the parent.
Member
There was a problem hiding this comment.
yeah I couldn't quite follow the logic, this seems right to me.
johnstep
approved these changes
Feb 24, 2026
benhillis
approved these changes
Feb 24, 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.
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
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed