Skip to content

Fix potential pipe deadlock when wslc's stdin doesn't support overlapped IO#14493

Merged
OneBlue merged 1 commit intofeature/wsl-for-appsfrom
user/oneblue/wslc-pipe-deadlock
Mar 23, 2026
Merged

Fix potential pipe deadlock when wslc's stdin doesn't support overlapped IO#14493
OneBlue merged 1 commit intofeature/wsl-for-appsfrom
user/oneblue/wslc-pipe-deadlock

Conversation

@OneBlue
Copy link
Collaborator

@OneBlue OneBlue commented Mar 20, 2026

Summary of the Pull Request

This change fixes a potential pipe deadlock that can happen where stdin is a pipe that doesn't support overlapped IO.

This can be reproduced by:

cat | wslc run -i debian:latest cat

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

@OneBlue OneBlue requested a review from a team as a code owner March 20, 2026 19:31
Copilot AI review requested due to automatic review settings March 20, 2026 19:31
Copy link
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 updates wslc’s non-TTY console relay path to reduce the risk of output pipe deadlocks when stdin reads can block, by moving stdin relaying out of the MultiHandleWait loop and into a dedicated thread.

Changes:

  • Always relay stdin in a dedicated thread for non-TTY processes (instead of conditionally using MultiHandleWait for non-interactive stdin).
  • Add/update comments describing the deadlock scenario and why a separate stdin relay path is needed.

Comment on lines +90 to +102
// Required because ReadFile() blocks if stdin doesn't support overlapped IO.
// This can create pipe deadlocks if we get blocked reading stdin while data is available on stdout / stderr.
// TODO: Will output CR instead of LF's which can confuse the linux app.
// Consider a custom relay logic to fix this.
inputThread = std::thread{[&]() {
try
{
wsl::windows::common::relay::InterruptableRelay(GetStdHandle(STD_INPUT_HANDLE), Stdin.get(), exitEvent.get());
}
CATCH_LOG();

Stdin.reset();
}};
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spawning a dedicated stdin relay thread helps keep stdout/stderr draining, but the thread is still joined via the scope-exit and InterruptableRelay() can block in ReadFile() (as the comment notes) in ways that are not interrupted by exitEvent. In that case RelayNonTtyProcess() can hang forever while joining inputThread after stdout/stderr complete. Consider making the stdin thread cancellation explicit (e.g., cancel synchronous I/O on the thread before join, or use a relay implementation that can be unblocked by the exit event for non-overlapped stdin).

Copilot uses AI. Check for mistakes.
@OneBlue OneBlue changed the title Fix potential pipe deadlock when wslc's stdin doesn't support overlap… Fix potential pipe deadlock when wslc's stdin doesn't support overlapped IO Mar 20, 2026
Copy link
Member

@dkbennett dkbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cherry picked and confirmed this fix also fixes the issue I had in E2E interactive tests for non-tty :shipit:

@OneBlue OneBlue merged commit bfd828a into feature/wsl-for-apps Mar 23, 2026
10 checks passed
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.

3 participants