Skip to content

Avoid distro zombie state when wsl init dies in systemd mode#40433

Open
chemwolf6922 wants to merge 3 commits intomasterfrom
user/wangfen/fix-wrong-state-after-wsl-init-dies-in-systemd-mode
Open

Avoid distro zombie state when wsl init dies in systemd mode#40433
chemwolf6922 wants to merge 3 commits intomasterfrom
user/wangfen/fix-wrong-state-after-wsl-init-dies-in-systemd-mode

Conversation

@chemwolf6922
Copy link
Copy Markdown
Contributor

@chemwolf6922 chemwolf6922 commented May 6, 2026

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

  • 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

Add test: UnitTests::UnitTests::SystemdKillInitTerminatesDistro

chemwolf6922 and others added 2 commits May 6, 2026 11:03
@chemwolf6922 chemwolf6922 requested a review from a team as a code owner May 6, 2026 03:12
Copilot AI review requested due to automatic review settings May 6, 2026 03:12
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 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-watcher entrypoint in the Linux init multicall binary and forks it when BootInit (systemd mode) is used.
  • Implements watcher logic using pidfd_open + poll() to detect wsl-init exit and then calls reboot(RB_POWER_OFF) to tear down the PID namespace.
  • Adds a Windows unit test that kills the presumed wsl-init PID 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.

Comment thread src/linux/init/init.cpp Outdated
Comment thread src/linux/init/init.cpp Outdated
Comment thread src/linux/init/init.cpp Outdated
Comment thread test/windows/UnitTests.cpp
Comment thread test/windows/UnitTests.cpp
Co-authored-by: Copilot <copilot@github.com>
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.

2 participants