Repository navigation
Description
Windows Version
Microsoft Windows [Version 10.0.26120.5751]
WSL Version
2.6.1.0
Are you using WSL 1 or WSL 2?
- WSL 2
- WSL 1
Kernel Version
6.6.87.2-1
Distro Version
Fedora release 42 (Adams)
Other Software
No response
Repro Steps
Environment
This is a confirmed regression, tested on two machines with the identical Windows build.
Working Environment
WSL Version: 2.5.10.0
Windows Version: 10.0.26120.5751
Failing Environment
WSL Version: 2.6.1.0
Windows Version: 10.0.26120.5751
Problem Description
On WSL version 2.6.1.0, the WSL2 VM instance shuts down approximately 15-20 seconds after the last terminal window is closed, even when a systemd service is in a stable active (running) state.
This behavior does not occur on the older WSL version 2.5.10.0 on the exact same Windows build, where the instance correctly remains active.
Steps to Reproduce
Ensure you are running WSL version 2.6.1.0 or later on a system with systemd=true enabled in /etc/wsl.conf.
Create a minimal systemd system service file at /etc/systemd/system/keep-alive.service:
[Unit]
Description=Test service to keep WSL active
[Service]
ExecStart=/bin/sleep infinity
[Install]
WantedBy=multi-user.target
Enable and start the service: sudo systemctl enable --now keep-alive.service.
Verify the service is active and stable: sudo systemctl status keep-alive.service.
Close all open WSL terminal windows.
Open a new PowerShell terminal and monitor the output of wsl -l -v.
Expected Behavior
The WSL instance should remain in the Running state indefinitely, as long as the keep-alive.service is active. This is the behavior seen in WSL version 2.5.10.0.
Actual Behavior
The WSL instance changes from the Running state to the Stopped state within 15-20 seconds after the last terminal is closed.
Additional Context
This is a confirmed regression. I reproduced this issue by upgrading a machine from the working v2.5.10.0 to the failing v2.6.1.0. The issue appeared immediately after the upgrade.
Troubleshooting has confirmed this is not a user configuration issue. There is no .wslconfig file in use, and /etc/wsl.conf is standard. The issue occurs with any systemd system service, not just a specific one.
Expected Behavior
I'd expect the same behavior on 2.6.1.0 as seen in 2.5.10.0, which is a running and active systemd service prevents WSL2 from shutting down the instance even after all running terminals are closed.
Actual Behavior
On 2.6.1.10 after about 20 seconds, WSL2 shuts down the instance after the last terminal is closed even though there is a running and active systemd service.
Diagnostic Logs
No response
Activity
github-actions commentedon Aug 21, 2025
Logs are required for review from WSL team
If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.
How to collect WSL logs
Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
The script will output the path of the log file once done.
If this is a networking issue, please use collect-networking-logs.ps1, following the instructions in Collect WSL logs for networking issues
Once completed please upload the output files to this GitHub issue.
See Collect WSL logs (recommended method).
If you choose to email these logs instead of attaching them to the bug, please send them to wsl-gh-logs@microsoft.com with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.
pmyers commentedon Aug 21, 2025
/question
Regarding getting logs for this via collect-wsl-logs.ps1 as required...
I cannot reproduce the issue when that log script is running, as it appears the log script itself is keeping WSL2 from terminating the instance. I can reproduce it 100% of the time, but only when that logging script is not running.
I debugged your collect logs script and found that as long as there is an active wpr.exe -start running in the background, WSL2 will not exit the instance. But as soon as wpr.exe -stop is run, it will exit shortly afterwards.
This means that the debugging tool (the log collection via wpr.exe) is itself influencing the results, and therefore we can't use this debugging tool to capture results (at least not the way the ps1 script is currently invoking it).
If you have some other advice for how to capture logs here, without having the log capture influence the reproducibility of the issue, please advise.
ctykk commentedon Aug 29, 2025
try https://github.com/gardengim/keepwsl
pmyers commentedon Aug 29, 2025
Thanks ctykk (@ctykk). I already had something very similar to this installed and running, and that worked fine to keep WSL2 alive in the past. But I also have other persistent systemd services like open-webui and insync running as well, so those should have also helped keep WSL2 alive. As mentioned, I've shown that this is a regression between the current release (2.5.10.0) and the preview release (2.6.1.0).
magicdude4eva commentedon Oct 14, 2025
Frustrating that this issue exists, any view when this can be resolved? Really pointless to have a distro running with docker and other system services and it terminates.
magicdude4eva commentedon Oct 15, 2025
Update: I downgraded to 2.5.10 and can re-produce this also on 2.5.10. Details:
Services and dockerd start when entering the distro
wsl -d wsl-containers-0.2.0:Also on 2.5.10.0 the distro shuts down when exiting the distro shell:
Reproduced this in the logs:
09:33:20 - brought up distro via
wsl -d wsl-containers-0.2.0Containers are running and after
docker psexited the distroAt 09:33:44 the distro stops:
Log-file
WslLogs-2025-10-15_09-14-11.zip
magicdude4eva commentedon Oct 15, 2025
To rule out any regressions, I validated this behaviour also in
To reproduce, install Ubuntu 22.04 and docker - install steps:
Exit the interactive shell and do "wsl -l -v" and you will see that after 15 seconds the distro stops:
FWIW - a "keep-alive" service keeps the distro up:
nebulon42 commentedon Oct 15, 2025
For me on Windows 10.0.22631.5909 and WSL 2.5.10.0 a fresh Ubuntu with
systemd=truein/etc/wsl.conf(by default) with the Docker sytemd service running and a container withdocker run -d --name keep-alpine --restart unless-stopped alpine:3.20 sleep infinityalso exits after closing the terminal.Edit: I read that this behavior might be by design although surprising.
chemwolf6922 commentedon Mar 18, 2026
I created this app a while ago to keep my docker engine alive (not docker desktop) in wsl: https://github.com/chemwolf6922/WSL-Keep-Alive.
This would also start wsl on login if configured.
(This is a hobby project as a WSL user, not representing any MS opinion nor is this an official solution.)
comxtohr commentedon Aug 10, 2026
Still reproducible on WSL 2.7.3.0 (Windows 11 26200.8875, Ubuntu 26.04,
systemd=true).Adding a few data points that I did not see covered above, in case they save someone else the debugging time — it cost me several hours tonight.
Symptom is timed, not idle-based. In my case the distro is torn down consistently 15 seconds after the last Windows-side caller exits. From
frpslogs on the other end of an frp tunnel running inside the distro:Inside the distro the last thing in the journal is always:
So from the guest's point of view this is a clean, externally-requested poweroff — not a crash and not something the guest decides.
Things that do NOT help (all tested on 2.7.3.0):
vmIdleTimeoutin.wslconfig— tried-1and2147483647, with correct CRLF/UTF-8 encoding, verified the file is read back correctly. No effect.loginctl enable-lingerfor the user — was already enabled; does not prevent the poweroff./etc/systemd/logind.conf.d/withHandlePowerKey=ignore,IdleAction=ignore,KillUserProcesses=no. No effect.sleep infinitysystemd system service — i.e. exactly thekeep-alive.servicefrom the original report. Confirmed no effect, as Perry Myers (@pmyers) said.One thing to warn people away from: I tried
systemctl mask poweroff.targetas a blunt workaround. Do not do this — it breaks the systemd user session (Failed to start the systemd user session for '<user>'), and the distro then dies immediately on every boot.systemctl unmask poweroff.targetrestores it.What does work is the approach several people already mentioned — hold a Windows-side process open. For anyone who wants it without an extra tool, a plain Scheduled Task is enough:
No admin rights needed, survives logoff/logon, and restarts itself if the holder process ever dies. After adding it the distro has stayed up continuously instead of dying every 15 seconds.
Measured before/after, watching the port from the far end of the tunnel so the probe itself could not wake the distro:
wsl-holderI also killed the holder task and ran
wsl --shutdown, to simulate a reboot: the task restarted, WSL came back, and every systemd service inside came back with it — no manual step.For completeness, the full arrangement that ended up being needed to run a long-lived service inside WSL reliably. The
wsl-holdertask is the fix for this issue; the rest is what it took to make the whole thing survive unattended, and may be useful context for anyone doing the same:wsl-holderscheduled task (above). This is the actual workaround.frpc) on Windows rather than inside WSL, so that remote access does not depend on the distro being alive. Without this, when WSL goes down you lose the very access you need to bring it back up. I learned this the hard way.Restart=always(not the packaged defaultRestart=on-failure) on the long-lived unit. When WSL is torn down this way the process exits 0, soon-failurewill not restart it.loginctl enable-lingerfor the service user, sosystemd --userunits start without an interactive login. Necessary but, as noted above, not sufficient on its own.Point 2 is the one I would emphasise: as long as this bug exists, anything you rely on for access should live outside the distro, not inside it.
This also lines up with Perry Myers (@pmyers)' observation that
collect-wsl-logs.ps1masks the bug: it is notwpr.exespecifically, it is simply that any live Windows-side process associated with the session keeps the VM from being reclaimed.The practical impact is worth restating: this makes WSL unusable as a host for anything long-running (tunnels, brokers, schedulers, docker) unless you also ship a babysitter process on the Windows side. In my case a
systemd --userservice that had been running fine for months started dying, and because the failure is silent — the service isenabled,Linger=yesis set, and nothing is logged as an error — it went unnoticed for days.fix(wsl): remove a wsl-ancora.service — ela nunca ancorou a VM
fix(win2): the daemon holds WSL open; pair --open for the Windows bro…
docs: 同步容器形态与 ComfyUI 切 WSL
chemwolf6922 commentedon Nov 20, 2026
Please set this option in
.wslconfigto disable the auto distro shutdown if you are facing this issue: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#general-wsl-settings