Giter Club home page Giter Club logo

Comments (6)

LGUG2Z avatar LGUG2Z commented on July 20, 2024 1

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.

LGUG2Z avatar LGUG2Z commented on July 20, 2024 1

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.

lhecker avatar lhecker commented on July 20, 2024

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.

lhecker avatar lhecker commented on July 20, 2024

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.

lhecker avatar lhecker commented on July 20, 2024

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.

zadjii-msft avatar zadjii-msft commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.