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: Avoid WINDOW_BUFFER_SIZE_EVENT when the viewport moves #15935

Merged

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Sep 6, 2023

SetConsoleWindowInfoImpl calls PostUpdateWindowSize, which emits a
CM_SET_WINDOW_SIZE event, which causes _InternalSetWindowSize to be
called, which calls ScreenBufferSizeChange which then finally emits a
WINDOW_BUFFER_SIZE_EVENT event into the client input buffer.

This messes up applications like which make use of
WINDOW_BUFFER_SIZE_EVENT to perform potentially lossy operations.
In case of SSH this results in a resize (SIGWINCH) of the server-side
screen which similarly may result in a response by the shell, etc.
Since that happens over networks and is async, and because our conhost
VT viewport implementation appears to have a number of subtle bugs,
this results in duplicate output lines (sometimes hundreds).

Under Windows Terminal this issue is not as apparent, since ConPTY has
no viewport that can be moved and no scrollback. It only appears as an
issue if a terminal application reacts poorly to the SIGWINCH event.

Closes #15769

Validation Steps Performed

  • Set a breakpoint in SynthesizeWindowBufferSizeEvent
  • Launch WSL and cause the viewport to move down
    No calls to SynthesizeWindowBufferSizeEvent
  • Execute tput reset
    Input line moves to row 0 ✅

@microsoft-github-policy-service microsoft-github-policy-service bot added Issue-Bug It either shouldn't be doing this or needs an investigation. Area-VT Virtual Terminal sequence support Product-Conhost For issues in the Console codebase labels Sep 6, 2023
@github-actions

This comment has been minimized.

@zadjii-msft
Copy link
Member

Wait does this do anything about #281?

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Thanks for mentioning and briefly going over this in Triage 😊

@lhecker
Copy link
Member Author

lhecker commented Sep 12, 2023

Wait does this do anything about #281?

No, that'd be a breaking change at this point, so this PR just avoids calling SetConsoleWindowInfo.
...but I think we should do that breaking change anyways very soon. It's only been 6 years since WINDOW_BUFFER_SIZE_EVENT was broken, but it's been >20 years before that. We should revert it, introduce separate messages and opt-ins or similar. The longer we wait the worse it gets IMO. (Especially since that the issue was reported 5 years ago, which is a bit of an oof for us.)

@lhecker lhecker added the AutoMerge Marked for automatic merge by the bot when requirements are met label Sep 18, 2023
@microsoft-github-policy-service microsoft-github-policy-service bot merged commit 741633e into main Sep 18, 2023
17 checks passed
@microsoft-github-policy-service microsoft-github-policy-service bot deleted the dev/lhecker/15769-duplicate-output branch September 18, 2023 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support 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. Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenConsole: Duplicate output lines when connecting to Ubuntu via SSH
3 participants