Comments (6)
Updates have already been made on our side to protect against any other applications which might exhibit this kind of non-standard WinEvent
behaviour in the future (referenced commit above).
I wonder if the same issue will happen if you kill a process with the task manager
I can confirm this is not the case; applications killed from the Task Manager send EVENT_OBJECT_DESTROY
.
A lot of applications, and not just Windows Terminal, use
TerminateProcess
komorebi
users are pretty quick and vocal to report issues like these, and with tens of thousands of users across a variety of professions using a breadth of both modern and legacy applications, Windows Terminal is the only application which has been reported to exhibit this behaviour.
If and when there are more examples from other applications I will be happy to share them, but for now, if 99% of other applications windows are doing the right thing (sending the appropriate WinEvent
when they are destroyed), I think it's worth trying to bring WT into conformance with the expected application behaviour in the Windows ecosystem.
from terminal.
Unfortunately I'm not well versed enough with CPP to offer much meaningful insight, but I created something similar using windows-rs
here: https://gist.github.com/LGUG2Z/da57d4f1fb294266e3793348b149fb79
[src\main.rs:126:5] state = {
"C:\\Windows\\explorer.exe": 3,
"C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminal_1.19.11213.0_x64__8wekyb3d8bbwe\\WindowsTerminal.exe": 2,
"C:\\Windows\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartMenuExperienceHost.exe": 5,
}
I'm tracking the state in a hashmap keyed by the exe path, incrementing by 1 whenever a create event comes through, decrementing by 1 whenever a destroy event comes through, and removing from the map when we drop to 0.
For when OpenProcess calls might fail, there is another hashmap keyed with the HWND to look up the exe path if the API call fails.
With this I can see that there are a few lingering create events between opening and closing instances of WT that don't have corresponding destroy events, and I'm betting these are for the visible window that interaction happens with 🤔
from terminal.
I'm somewhat surprised that the OS doesn't do that for us. We use TerminateProcess
on exit to work around issues in WinUI (in particular on Windows 10). It's a simple and effective solution.
While I can see how we should try to emit these events on exit, I'm not sure whether that would help your project at all. A lot of applications, and not just Windows Terminal, use TerminateProcess
and I wonder if the same issue will happen if you kill a process with the task manager. Since TerminateProcess
is an entirely valid way to exit an application I'm not sure whether calling Windows Terminal buggy is fair.
But in any case, I suppose you'd need to make your window manager robust against sudden process exits independent of whether we address this issue or not.
from terminal.
I've hacked this C++ snippet together as a test case for this issue: https://gist.github.com/lhecker/82b029643e9f9ccf15304a623093880b
For any given application name, it records a set of HWNDs. They're added to the set on EVENT_OBJECT_CREATE
and removed on EVENT_OBJECT_DESTROY
. Currently, when opening/closing the window the counter for WindowsTerminal.exe will constantly increase.
However, I'm doing something wrong in that code, because the same thing happens for VS Code and other applications:
AW5Sm4xuRzrM4pUi.mp4
Since it happens with pretty much all applications, I must be doing something wrong but I can't figure out what. @LGUG2Z I don't mean to bother you unnecessarily, but if you can spot any flaws with what I described above, or any flaws in my code, please let me know. 🙂
from terminal.
Just after writing that comment, I finally figured out the first mistake I made! Apparently, when a EVENT_OBJECT_DESTROY
is received, OpenProcess
may not work anymore. In my first version I did an early return in that case.
I've now changed the code to instead search through all windows and that gets VS Code down to just 0 to 1 HWND leaks per launch. But that's the same amount as for Windows Terminal. Weird. Am I checking some of the callback parameters incorrectly? 🤔
from terminal.
Thoughts:
- Is this just a XAML islands thing? I think PerceptionSimulationInput (or something like that) in system32 is also XAML islands, but this might be gone in certain win11 builds.
- Is this a RuntimeBroker thing? maybe if we're the defterm, the monarch process is still running?
- Maybe the tray icon is still present (but not cleaned up cause {{bug number here}}, and that's why we're not having that event emitted?
- Does this repro with the default terminal settings?
allowHeadless
,minimizeToNotificationArea
, and_quake
mode come to mind
we honestly don't know! We should find someone who does
from terminal.
Related Issues (20)
- ClosePseudoConsole does not close the process handle to conhost HOT 3
- Arabic rendered as Left to Right HOT 2
- error 2147942487 HOT 3
- Allow remapping of experimental.repositionCursorWithMouse to use key bindings such as Alt + Left Click HOT 2
- The Thai language displays incorrectly in the Windows terminal. HOT 2
- [Windows Terminal]: Name of the current tab is not visible in high contrast desert theme.
- [Windows Terminal - Command Palette]: 'Shortcut keys' in 'Command Palette' are not visible in high contrast themes for focused or hovered rows.
- [Windows Terminal - Settings]: 'Settings' tab does not open in high contrast 'Aquatic' or 'Desert' themes.
- [Windows Terminal - Settings - Defaults]: Unable to navigate 'Font face' suggestions using keyboard in Appearance settings. HOT 1
- keybindings marked deprecated in preview $schema HOT 3
- Terminal runs as an administrator but no response HOT 2
- Starting Admin PowerShell Terminal window via taskbar right-click opens multiple windows HOT 1
- Command line "-F" (fullscreen) in an already running instance? HOT 4
- changing the app name independently of the language settings HOT 1
- Clipboard gets overridden when pasting to a tab with a previous selection with right click or Shift+Insert, when copy-on-select is enabled HOT 2
- Large drop in performance when using font features HOT 3
- After entering the font, a black color block will appear when rolling back HOT 2
- Bell not silent despite bellStyle being set to "none" HOT 2
- Add support for the S8C1T/S7C1T escape sequences HOT 2
- Cannot install/update Windows Terminal: error 0x80070005 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminal.