Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConPTY: Fix a shutdown deadlock with WSL #16340

Merged
merged 1 commit into from
Nov 21, 2023

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Nov 19, 2023

Under normal circumstances this bug should be rare as far as I can
observe it on my system. However, it does occur randomly.

In short, WSL doesn't pass us anonymous pipes, but rather WSA sockets
and those signal their graceful shutdown first before being closed
later by returning a lpNumberOfBytesRead of 0 in the meantime.

Additionally, VtIo synchronously pumps the input pipe to get the
initial cursor position, but fails to check _exitRequested.
And so even with the pipe handling fixed, VtIo will also deadlock,
because it will never realize that VtInputThread is done reading.

Validation Steps Performed

  • Build commit 376737e with this change and replace conhost with it
    Coincidentally it contains a bug (of as of yet unknown origin)
    due to which the initial cursor position loop in VtIo never
    completes. Thanks to this, we can easily provoke this issue.
  • Launch WSL in conhost and run an .exe inside it
  • Close the conhost window
  • Task manager shows that all conhost instances exit immediately

@lhecker lhecker added Product-Conpty For console issues specifically related to conpty Area-Input Related to input processing (key presses, mouse, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) zInbox-Bug Ignore me! labels Nov 19, 2023
@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Nov 21, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit adb0472 into main Nov 21, 2023
17 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the dev/lhecker/wsl-exit-deadlock branch November 21, 2023 20:50
DHowett pushed a commit that referenced this pull request Dec 4, 2023
Under normal circumstances this bug should be rare as far as I can
observe it on my system. However, it does occur randomly.

In short, WSL doesn't pass us anonymous pipes, but rather WSA sockets
and those signal their graceful shutdown first before being closed
later by returning a `lpNumberOfBytesRead` of 0 in the meantime.

Additionally, `VtIo` synchronously pumps the input pipe to get the
initial cursor position, but fails to check `_exitRequested`.
And so even with the pipe handling fixed, `VtIo` will also deadlock,
because it will never realize that `VtInputThread` is done reading.

## Validation Steps Performed
* Build commit 376737e with this change and replace conhost with it
  Coincidentally it contains a bug (of as of yet unknown origin)
  due to which the initial cursor position loop in `VtIo` never
  completes. Thanks to this, we can easily provoke this issue.
* Launch WSL in conhost and run an .exe inside it
* Close the conhost window
* Task manager shows that all conhost instances exit immediately

(cherry picked from commit adb0472)
Service-Card-Id: 91152102
Service-Version: 1.19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Input Related to input processing (key presses, mouse, etc.) AutoMerge Marked for automatic merge by the bot when requirements are met Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-2 A description (P2) Product-Conpty For console issues specifically related to conpty zInbox-Bug Ignore me!
Projects
Development

Successfully merging this pull request may close these issues.

3 participants