microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.59k stars 8.31k forks source link

closePane vs. closeTab differences? #4484

Open nicholas-ochoa opened 4 years ago

nicholas-ochoa commented 4 years ago

Environment

Windows build number: 10.0.18362.592
Windows Terminal version (if applicable): 0.8.10261.0

Any other software?
WSL 2 (Debian 10)
bash 5.0.3
OpenSSH_7.9p1 Debian-10+deb10u1, OpenSSL 1.1.1c

Not entirely sure where this lies, but starting here since I can't recreate it elsewhere (putty, cmd.exe)

When closing a WSL session by either middle mouse clicking the tab (NOT the X) or by running the "closeTab" command via a hotkey, my ssh session will terminate and the application that's running receives a SIGHUP.

When closing a WSL session by clicking the X on a tab or by running the "closePane" command via a hotkey, my ssh session will terminate and the application that's running receives both SIGUSR1 (first) and SIGHUP.

This isn't an issue per se, but I'm trying to track down a bug in our own application and part of it seems to be related to how the application was terminated. Our end users don't use Windows Terminal, but in trying to understand how to create this scenario I've been working through different SSH clients.

What does Windows Terminal do differently when closing a tab using "closePane" versus "closeTab"?

DHowett-MSFT commented 4 years ago

So! Pane teardown and tab teardown follow the same path for terminating a connection, unless the tab being closed is the last one. If it's the last one, the console host gets terminated before the application does and it becomes rather upset. Is it your last tab?

nicholas-ochoa commented 4 years ago

No - when I was testing I had multiple tabs open and was just adding a new tab, connecting to SSH, then closing that new tab via middle mouse click or clicking on the X.

It sounds like it's still taking a different path somehow, since the behavior does differ slightly.

zadjii-msft commented 2 years ago

Hey so this question's been open for a while now, but I concur, both actions should be following the same path. This was nearly 2 years ago now, so it's possible that we were leaking a control in one path but not the other, but at this point, that certainly shouldn't be the case anymore.

@nicholas-ochoa you still seeing this?

nicholas-ochoa commented 2 years ago

I ran through some additional scenarios and found more discrepencies. This was on Windows Terminal Preview version: 1.12.2931.0.

For each scenario with Windows Terminal, I am opening a Bash (git for windows) shell, then executing ssh user@server and running my app.

Single tab open:

Two tabs open:

For comparison, using Putty:

zadjii-msft commented 2 years ago

well that's wild. I Have no idea why those would be different. I ESPECIALLY don't know why "Use hotkey to run Close Tab" would be different from "Open command palette and select Close Tab" - those literally do the same thing. (smae idea with all the other hotkey vs command palette versions of an action). They both dispatch the exact same kind of closeTab action.

Maybe there's something weird with the teardown order of the ConPTY that's nondeterministic here? No idea. We'd probably have to find out where in git bash they're raising different kinds of signals, and seeing which of those is connected to which console teardown paths. I've honestly got no idea, since we're not really the one's sending the SIGUSR1 or the SIGHUP ourselves.

zadjii-msft commented 1 year ago

~Hmm. Maybe I'm seeing this during #14843. Idly I wonder if closing the last tab goes down some different path that ends up not releasing the last tab or the TerminalPage in general for some reason.~

I'm entirely wrong. The lack of a TerminalPage dtor that I'm seeing in #14843 doesn't repro on main, so it's gotta be something else

I was crazy off base. The leak I was seeing was entirely my fault, and unrelated to this.

zadjii-msft commented 1 year ago

Hey does this still repro on 1.18/? There've been a lot of changes in how process lifetimes are tracked in the last... 3 years...

nicholas-ochoa commented 1 year ago

Windows Terminal Preview version: 1.18.1462.0

For each scenario with Windows Terminal, I am opening a Bash (git for windows) shell, then executing ssh user@server and running my app.

Single tab open:

Two tabs open, tab focused is my app:

Two tabs open, tab focused is my NOT app:

The results are weirdly inconsistent with what I documented previously. Is it possible that WT is sending BOTH SIGHUP and SIGUSR1 at the same time?

DHowett commented 1 year ago

Wow, this is comprehensive!

Terminal mostly speaks the language of the console, so it's emitting a CTRL_CLOSE_EVENT or a CTRL_BREAK_EVENT or something that WSL is picking up. I don't know how they do signal mapping, but I do suspect that there is some difference based on when and how the console session terminates underneath them.

nicholas-ochoa commented 1 year ago

This is using Git for Windows bash / msys bash - not WSL.

DHowett commented 1 year ago

WHOOPS, That's what I get for doing a drive-by. Thanks! Most of the thought still stands -- we're sending some upstream signal of those or tearing down the console host before it's ready. I'll have to think about what tracing we'll need to figure this out :)

zadjii-msft commented 1 year ago

We've got a theory that this is some sort of weird race condition, somehow. Like, maybe if you ran 1000 of each of those tests[^1], it might come out inconsistently across each of them.

I have no idea how we'd begin to track down what part of the system this is coming from... 🤷

[^1]: we are not actually asking you to run those tests 1000 times 😅

e-nikolov commented 10 months ago

Not sure if this is a related issue or a separate one:

  1. Open Windows Terminal - there is a single tab (Tab 1)
  2. Open a new tab (Tab 2)
  3. Press the shortcut for the closePane command
    • Tab 2 closes - expected (since it has only a single pane)
  4. Press the shortcut for the restoreLastClosed command
    • Tab 2 is restored as a pane of Tab 1 - unexpected, I would expect that since the closePane command closed the entire Tab 2, it should restore it as a tab rather than a pane

A side issue is that as far as I can tell the restoreLastClosed command is not documented on this page https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions