closePane vs. closeTab differences? #6314

Open
opened 2026-01-31 00:35:36 +00:00 by claunia · 13 comments
Owner

Originally created by @nicholas-ochoa on GitHub (Feb 5, 2020).

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"?

Originally created by @nicholas-ochoa on GitHub (Feb 5, 2020). # Environment ```none 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"?**
claunia added the Help WantedIssue-BugArea-ServerProduct-ConptyPriority-2 labels 2026-01-31 00:35:36 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 10, 2020):

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?

@DHowett-MSFT commented on GitHub (Feb 10, 2020): 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?
Author
Owner

@nicholas-ochoa commented on GitHub (Feb 10, 2020):

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.

@nicholas-ochoa commented on GitHub (Feb 10, 2020): 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.
Author
Owner

@zadjii-msft commented on GitHub (Dec 9, 2021):

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?

@zadjii-msft commented on GitHub (Dec 9, 2021): 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?
Author
Owner

@nicholas-ochoa commented on GitHub (Dec 9, 2021):

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:

  • Clicking the "X" to close the tab: SIGHUP
  • Middle mouse button click on the tab to close the tab: SIGUSR1
  • Open command palette and select Close Tab: SIGHUP
  • Open command palette and select Close Pane: SIGHUP
  • Open command palette and select Close Window: SIGHUP
  • Use hotkey to run Close Tab: SIGUSR1
  • Use hotkey to run Close Pane: SIGHUP
  • Use hotkey to run Close Window: SIGHUP
  • Close application by clicking the application window "X": SIGHUP
  • Right clicking taskbar icon and selecting "Close Window": SIGHUP

Two tabs open:

  • Clicking the "X" to close the tab: SIGHUP.
  • Middle mouse button click on the tab to close the tab: SIGHUP
  • Open command palette and select Close Tab: SIGUSR1
  • Open command palette and select Close Pane: SIGHUP
  • Open command palette and select Close Window: SIGUSR1
  • Use hotkey to run Close Tab: SIGHUP
  • Use hotkey to run Close Pane: SIGUSR1
  • Use hotkey to run Close Window: SIGHUP
  • Close application by clicking the application window "X": SIGUSR1
  • Right clicking taskbar icon and selecting "Close Window": SIGHUP

For comparison, using Putty:

  • Clicking on the application window "X" and then confirming that I want to close the session: SIGUSR1
  • Right clicking taskbar icon and selecting "Close Window" then confirming that I want to close the session: SIGHUP
@nicholas-ochoa commented on GitHub (Dec 9, 2021): 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: - Clicking the "X" to close the tab: `SIGHUP` - Middle mouse button click on the tab to close the tab: `SIGUSR1` - Open command palette and select `Close Tab`: `SIGHUP` - Open command palette and select `Close Pane`: `SIGHUP` - Open command palette and select `Close Window`: `SIGHUP` - Use hotkey to run `Close Tab`: `SIGUSR1` - Use hotkey to run `Close Pane`: `SIGHUP` - Use hotkey to run `Close Window`: `SIGHUP` - Close application by clicking the application window "X": `SIGHUP` - Right clicking taskbar icon and selecting "Close Window": `SIGHUP` Two tabs open: - Clicking the "X" to close the tab: `SIGHUP`. - Middle mouse button click on the tab to close the tab: `SIGHUP` - Open command palette and select `Close Tab`: `SIGUSR1` - Open command palette and select `Close Pane`: `SIGHUP` - Open command palette and select `Close Window`: `SIGUSR1` - Use hotkey to run `Close Tab`: `SIGHUP` - Use hotkey to run `Close Pane`: `SIGUSR1` - Use hotkey to run `Close Window`: `SIGHUP` - Close application by clicking the application window "X": `SIGUSR1` - Right clicking taskbar icon and selecting "Close Window": `SIGHUP` For comparison, using Putty: - Clicking on the application window "X" and then confirming that I want to close the session: `SIGUSR1` - Right clicking taskbar icon and selecting "Close Window" then confirming that I want to close the session: `SIGHUP`
Author
Owner

@zadjii-msft commented on GitHub (Dec 9, 2021):

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 on GitHub (Dec 9, 2021): 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.
Author
Owner

@zadjii-msft commented on GitHub (Feb 15, 2023):

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 on GitHub (Feb 15, 2023): ~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.
Author
Owner

@zadjii-msft commented on GitHub (May 31, 2023):

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...

@zadjii-msft commented on GitHub (May 31, 2023): 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...
Author
Owner

@nicholas-ochoa commented on GitHub (Jun 1, 2023):

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:

  • Clicking the "X" to close the tab: SIGUSR1
  • Middle mouse button click on the tab to close the tab: SIGUSR1
  • Open command palette and select Close Tab: SIGHUP
  • Open command palette and select Close Pane: SIGHUP
  • Open command palette and select Close Window: SIGHUP
  • Use hotkey to run Close Tab: SIGHUP
  • Use hotkey to run Close Pane: SIGUSR1
  • Use hotkey to run Close Window: SIGHUP
  • Close application by clicking the application window "X": SIGHUP
  • Right clicking taskbar icon and selecting "Close Window": SIGHUP

Two tabs open, tab focused is my app:

  • Clicking the "X" to close the tab: SIGHUP.
  • Middle mouse button click on the tab to close the tab: SIGHUP
  • Open command palette and select Close Tab: SIGHUP
  • Open command palette and select Close Pane: SIGHUP
  • Open command palette and select Close Window: SIGHUP
  • Use hotkey to run Close Tab: SIGUSR1
  • Use hotkey to run Close Pane: SIGHUP
  • Use hotkey to run Close Window: SIGHUP
  • Close application by clicking the application window "X": SIGUSR1
  • Right clicking taskbar icon and selecting "Close Window": SIGHUP

Two tabs open, tab focused is my NOT app:

  • Clicking the "X" to close the tab: SIGHUP.
  • Middle mouse button click on the tab to close the tab: SIGHUP
  • Open command palette and select Close Other Tabs: SIGUSR1
  • Close application by clicking the application window "X": SIGHUP
  • Right clicking taskbar icon and selecting "Close Window": SIGHUP

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?

@nicholas-ochoa commented on GitHub (Jun 1, 2023): 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: - Clicking the "X" to close the tab: `SIGUSR1` - Middle mouse button click on the tab to close the tab: `SIGUSR1` - Open command palette and select `Close Tab`: `SIGHUP` - Open command palette and select `Close Pane`: `SIGHUP` - Open command palette and select `Close Window`: `SIGHUP` - Use hotkey to run `Close Tab`: `SIGHUP` - Use hotkey to run `Close Pane`: `SIGUSR1` - Use hotkey to run `Close Window`: `SIGHUP` - Close application by clicking the application window "X": `SIGHUP` - Right clicking taskbar icon and selecting "Close Window": `SIGHUP` Two tabs open, tab focused is my app: - Clicking the "X" to close the tab: `SIGHUP`. - Middle mouse button click on the tab to close the tab: `SIGHUP` - Open command palette and select `Close Tab`: `SIGHUP` - Open command palette and select `Close Pane`: `SIGHUP` - Open command palette and select `Close Window`: `SIGHUP` - Use hotkey to run `Close Tab`: `SIGUSR1` - Use hotkey to run `Close Pane`: `SIGHUP` - Use hotkey to run `Close Window`: `SIGHUP` - Close application by clicking the application window "X": `SIGUSR1` - Right clicking taskbar icon and selecting "Close Window": `SIGHUP` Two tabs open, tab focused is my NOT app: - Clicking the "X" to close the tab: `SIGHUP`. - Middle mouse button click on the tab to close the tab: `SIGHUP` - Open command palette and select `Close Other Tabs`: `SIGUSR1` - Close application by clicking the application window "X": `SIGHUP` - Right clicking taskbar icon and selecting "Close Window": `SIGHUP` 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?
Author
Owner

@DHowett commented on GitHub (Jun 1, 2023):

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.

@DHowett commented on GitHub (Jun 1, 2023): 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.
Author
Owner

@nicholas-ochoa commented on GitHub (Jun 1, 2023):

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

@nicholas-ochoa commented on GitHub (Jun 1, 2023): This is using Git for Windows bash / msys bash - not WSL.
Author
Owner

@DHowett commented on GitHub (Jun 1, 2023):

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 :)

@DHowett commented on GitHub (Jun 1, 2023): 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 :)
Author
Owner

@zadjii-msft commented on GitHub (Aug 23, 2023):

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 tests1 , 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 😅 ↩︎

@zadjii-msft commented on GitHub (Aug 23, 2023): 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 😅
Author
Owner

@e-nikolov commented on GitHub (Jan 4, 2024):

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

@e-nikolov commented on GitHub (Jan 4, 2024): 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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6314