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

Ctrl+Break can leave the WSL shell in an unusable state #18425

Open
j4james opened this issue Jan 14, 2025 · 6 comments
Open

Ctrl+Break can leave the WSL shell in an unusable state #18425

j4james opened this issue Jan 14, 2025 · 6 comments
Labels
Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.

Comments

@j4james
Copy link
Collaborator

j4james commented Jan 14, 2025

Windows Terminal version

1.22.2702.0

Windows build number

10.0.19045.5247

Other Software

VIM 8.2.4919 (inside WSL)

Steps to reproduce

  1. Open the Settings, and set the Profile termination behavior to Close only when process exits successfully.
  2. Start a WSL shell and run vim.
  3. Enter :set mouse=a to enable mouse mode.
  4. Press Ctrl+Break (possibly Ctrl+ScrLock depending on your keyboard).
  5. When you see the press Enter to restart message, press Enter.
  6. Once the shell restart, try clicking in the window to select some text.

Expected Behavior

I'd expect mouse selection to work.

Actual Behavior

When you click in the window, nothing can be selected, but a bunch of "random" characters get entered at the prompt. It seems that Ctrl+Break kills the session without giving the app a chance to exit gracefully, and then when we restart the session we don't reset any of the VT state either. As a result we're left with a mouse mode enabled which the shell wasn't expecting.

This mouse mode example was just the easiest to demonstrate, but you can see how it could be even more annoying if the app had enabled something like win32 input mode, or had selected a graphic character set.

Note that for Windows console apps this is less of a problem, because they can trap the break and block it, or at least shut down more gracefully. But I don't think there is anything that Linux apps can do about this, because it's the WSL session itself that is being aborted (at least that's what appears to be happening).

@j4james j4james added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jan 14, 2025
@WhatsACloud
Copy link

Managed to reproduce the bug on version 1.21.3231.0 of windows terminal, and version 23H2 of windows 11.

Bug also appears to go away if you enter vim, do :set mouse = a, then exit vim normally using :q.

will investigate further later.

@j4james
Copy link
Collaborator Author

j4james commented Jan 15, 2025

You can also just type reset to get the terminal back to a usable state, but ideally that should be something the terminal does itself when restarting a session. In fact it would be best if it did that before it even displayed the process exit message, because otherwise that can be unreadable. So maybe at the start of this method, or wherever this is called from.

void ConptyConnection::_indicateExitWithStatus(unsigned int status) noexcept
{
try
{
// GH#11556 - make sure to format the error code to this string as an UNSIGNED int
const auto msg1 = RS_fmt(L"ProcessExited", _formatStatus(status));
const auto msg2 = RS_(L"CtrlDToClose");
const auto msg = fmt::format(FMT_COMPILE(L"\r\n{}\r\n{}\r\n"), msg1, msg2);
TerminalOutput.raise(msg);
}
CATCH_LOG();
}

It doesn't necessarily have to be be a hard reset, but at least a soft reset and then whatever additional modes are required to get the input back to normal.

@carlos-zamora
Copy link
Member

Thanks for filing! RestartConnection() should fix this. Just a matter of calling the API on our end. 🙂

@carlos-zamora carlos-zamora added this to the Terminal v1.24 milestone Jan 15, 2025
@carlos-zamora carlos-zamora added Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jan 15, 2025
@github-project-automation github-project-automation bot moved this to To Cherry Pick in 1.22 Servicing Pipeline Jan 15, 2025
@WhatsACloud
Copy link

I'll fix this issue and submit a PR for it by this week.

@WhatsACloud
Copy link

@carlos-zamora I tried running RestartConnection() from the command palette but it doesn't appear to fix the issue.

What do you think of running the command "reset" when the user presses ctrl + break (but before the SIGKILL is sent), or after the user presses "enter" to restart?

@WhatsACloud
Copy link

Fixed this issue in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalConnection Issues pertaining to the terminal<->backend connection interface Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal.
Projects
Status: To Cherry Pick
Development

No branches or pull requests

3 participants