wsl.exe discards the calling Windows process's stdin even when the guest command never reads it

Open
#42,094 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp

Research direction

The report provides a cmd.exe reproduction showing that wsl.exe -- true consumes piped stdin, while --help and --status do not; it names no source files or tests. Start by finding the Windows-side code that launches guest commands and forwards stdin, then trace how that path differs for help and status. Done means the behavior is corrected or made controllable as the issue discussion decides, with the repro cases checking the result.

Written by the indexing model from the issue text.

Description

feature wsl2
Windows Version

Microsoft Windows [Version 10.0.29695.1001]

WSL Version

3.0.3.0 (WSLg 1.0.79, MSRDC 1.2.7391). First seen on 2.7.14.0 and reproduced
unchanged on 3.0.3.0 after wsl --update.

Are you using WSL 1, WSL 2, or WSLC?
  • WSL 1
  • WSL 2
  • WSLC
Kernel Version

6.18.54.1-1

Distro Version

Ubuntu 26.04.1 LTS

Other Software

None. The repro below is cmd.exe only.

Repro Steps
@echo off
echo [1] control, no wsl -- expect "hello"
echo hello | cmd /c "cmd /c exit & findstr ."

echo [2] wsl.exe -- true -- expect "hello"
echo hello | cmd /c "wsl.exe -- true & findstr ."

echo [3] wsl.exe --help, never enters the guest
echo hello | cmd /c "wsl.exe --help > nul 2>&1 & findstr ."

echo [4] workaround, stdin redirected from NUL
echo hello | cmd /c "wsl.exe -- true < NUL & findstr ."

true is used deliberately: the guest command exits immediately and never reads
a byte of stdin.

Expected Behavior

All four print hello. wsl.exe -- true does not read stdin on behalf of a
guest command that does not read stdin, so the bytes are still there for the
next command in the pipeline.

Actual Behavior
[1] control, no wsl -- expect "hello"
hello

[2] wsl.exe -- true -- expect "hello"
                              <-- empty: the bytes are gone

[3] wsl.exe --help, never enters the guest
hello

[4] workaround, stdin redirected from NUL
hello

Case [3] is the interesting one: invocations that never enter the guest
(--help, --status) leave stdin alone, so the drain is tied to launching a
guest command rather than to running wsl.exe as such.

How much is lost depends on what happens to be buffered at that moment. A small
write followed by EOF disappears completely; a 1 MB stream still being written
survives, because wsl.exe only takes what is available. That is what makes
this so hard to attribute in practice -- it looks intermittent and
data-dependent.

Why this is not simply #11439

#11439 (and
#10429 before it) covered the
Linux to Windows direction -- running cmd.exe from inside a WSL shell eats
the Linux-side stdin -- and was closed as by design, with the rationale that WSL
pipes stdin to the Windows side and cannot know whether the Windows command
consumes it.

This report is the Windows to Linux direction: wsl.exe on the Windows side
discarding the stdin of the Windows process that invoked it. I am raising it
separately because the trade-off looks different here:

  • wsl.exe is a Windows CLI, so unlike the interop case there is an obvious
    place to put an opt-out. There is currently no flag to suppress stdin
    forwarding (-n is taken by --no-launch for --install). ssh has had
    -n for exactly this reason.
  • wslc, the container CLI shipped in this same 3.0.3.0 package, already models
    it the other way round: wslc exec and wslc create take
    -i, --interactive -- "Attach to stdin and keep it open" -- so stdin is
    attached only when asked for. wsl.exe forwards it unconditionally and
    offers no way to decline.
  • The behaviour is not documented in wsl --help or in the CLI docs, and it
    destroys data with no diagnostic.
  • --help and --status not draining shows the relay is already conditional,
    so the condition could plausibly be refined.

If the relay itself must stay as it is, a documented --no-stdin flag (or a
note in the docs and --help) would be enough to make this diagnosable.

How this was found, as an illustration of the cost

wsl.exe was called once in a PowerShell profile, to probe for a config file:

if ((gcm -ea ignore wsl) -and (wsl -- ls '~/.tmux-pwsh.conf' 2>$null)) {

That profile also serves as the DefaultShell for Win32-OpenSSH. PowerShell
loads profiles even for non-interactive -c sessions
(PowerShell/PowerShell#24411),
so every scp and sftp connection to the machine ran that line first, which
swallowed the client's protocol greeting -- scp and sftp then hung forever
with no error on either end. Two days went into blaming PowerShell, Win32-OpenSSH
and MSIX packaging before the profile line turned out to be responsible. The fix
on my side is to hand wsl.exe an empty pipe:

$null | wsl -- ls '~/.tmux-pwsh.conf' 2>$null

Noting it here only because a silent, buffer-dependent loss of stdin is
unusually expensive to track down, which seems worth weighing against the
"cannot know whether it is consumed" argument.

Diagnostic Logs

WslLogs-2026-10-28_12-42-29.tar.gz, collected with
diagnostics/collect-wsl-logs.ps1 while the repro above ran, is attached in a
comment below. (The collector's "press any key" wait was replaced by a call to
the repro script so it could run unattended; that is the only change to it, and
the trace therefore covers exactly the four cases.)

Dominant language
C++
Stars
34.4k
Forks
1.9k
Avg merge
1d 23h
Merged PRs (30d)
166

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/WSL

All issues in microsoft/WSL

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.