Avoid distro zombie state when wsl init dies in systemd mode#40433
Open
chemwolf6922 wants to merge 3 commits intomasterfrom
Open
Avoid distro zombie state when wsl init dies in systemd mode#40433chemwolf6922 wants to merge 3 commits intomasterfrom
chemwolf6922 wants to merge 3 commits intomasterfrom
Conversation
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent WSL distributions from getting stuck in a “zombie” state when wsl-init dies while systemd mode is enabled, by introducing a lightweight watcher process that monitors wsl-init and triggers a PID-namespace teardown when it exits.
Changes:
- Adds a new
wsl-init-watcherentrypoint in the Linux init multicall binary and forks it whenBootInit(systemd mode) is used. - Implements watcher logic using
pidfd_open+poll()to detectwsl-initexit and then callsreboot(RB_POWER_OFF)to tear down the PID namespace. - Adds a Windows unit test that kills the presumed
wsl-initPID in systemd mode and verifies subsequent WSL commands succeed.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/windows/UnitTests.cpp | Adds a unit test to validate the distro recovers after wsl-init is killed in systemd mode. |
| src/shared/inc/lxinitshared.h | Introduces the LX_INIT_WSL_INIT_WATCHER name constant for the new entrypoint. |
| src/linux/init/init.cpp | Adds wsl-init-watcher dispatch, forks the watcher in systemd mode, and implements watcher behavior via pidfd monitoring and namespace teardown. |
Co-authored-by: Copilot <copilot@github.com>
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 PR adds a wsl-init-watcher process to monitor the wsl init when systemd mode is enabled.
The mini_init process monitors the process 1 of a distro to determine if the distro is alive. In non-systemd mode, that is the wsl init. In systemd mode, that will be the systemd init. And if the wsl init dies in systemd mode, the distro ends up in a zombie state. Where all wsl calls from Windows fail with "Catastrophic failure".
This PR works by adding a new process that monitors the wsl init in systemd mode. And requests a shutdown if the wsl init process died.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Add test: UnitTests::UnitTests::SystemdKillInitTerminatesDistro