-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Sometimes windows don't get persisted on a Windows Update #17179
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Yea, again today, I got both windows back, but the buffer state was what it was the previous time I had quit the Terminal. So, whatever happened during the update meant that the Terminal didn't actually persist the buffer. |
I found that this tool can be used for shutdown tests:
For instance: & "C:\Program Files (x86)\Windows Kits\10\App Certification Kit\rmlogotest.exe" (ps -Name WindowsTerminal).Id I couldn't reproduce any issues on the main branch, even with multiple windows that have multiple tabs, and no matter how I re-launched the app. |
tl;dr: handoff doesn't assign a I figured out how to reproduce multiple issues (probably even the issue):
|
So yea here's the thing - defterm wasn't involved (to the best of my knowledge) in my scenario. I almost never open things via defterm anymore - pretty sure Stable is set as my defterm handler. Normally quitting the terminal will persist just fine - there's something specific about updates that makes the terminal not persist the current state of the buffer 🤷 |
I don't know if this belongs here, but I've been having a hell of a time getting Terminal to save my buffer sessions. It works fine when I manually close Terminal. However pretty much the only reasons Terminal ever gets restarted in my experience is A) Windows updates or B) system crashes (yes I have some system issue that occasionally causes crashes). What I've noticed is that I can easily recreate the issue by simply killing the WindowsTerminal.exe or OpenConsole.exe processes. Notably, the behavior is different depending on which one is killed. Killing WindowsTerminal.exe simply fails to save any new buffer content to the existing buffer dump text file(s). Reopening Terminal restores the content in those files to the appropriate tabs, but any new buffer content during the previous run wasn't captured, so the content restored is incomplete. zadjii noted this behavior in the OP. However, killing OpenConsole.exe has far worse behavior. Killing all instances of OpenConsole.exe (apparently one for each tab) completely blows away (read: deletes) all buffer text files entirely. When reopening Terminal, not even the tabs are restored, and the one fresh tab that is created has no buffer content, as you would expect. This is the behavior I'm seeing every time I come back to my machine after a Windows update or a system crash. No tabs are restored, no buffer content is restored, and no buffer dump files exist. I have to assume that the restarts being performed even by successful Windows updates are not gracefully closing Terminal. So the new buffer functionality has been largely useless for me so far. If there were some way to force Terminal to update the buffer file on a schedule, before closing Terminal, this might be more useful, but even then, if it randomly decides to delete the buffer files when OpenConsole is force closed, then even that is not a solution. I considered implementing a custom solution which monitors my buffer dump files and backs them up, however even that wouldn't be useful, since Terminal doesn't actually update those files until it is gracefully closed. Personally, I would happily eat whatever performance hit would be required for Terminal to update my buffer dump files on a frequent, and/or configurable schedule (and of course not delete them when force closed). I'm sure that's not a universal opinion. |
We could check OpenConsole's exit code and see if it's neither 0 nor More importantly, I wonder if this is finally the clue as to why the buffer contents are lost on a windows update. Does the OS perhaps kill OpenConsole before it sends a termination message to Windows Terminal? That would definitely be a problem. |
Just for the record, I noticed that Terminal has a couple of other child processes, but I didn't get around to testing what happens when I kill those. Once I saw the behavior of killing OpenConsole.exe I called it quits. Also, I will add that by "killing processes" I mean using Task Manager's "Details" tab, right clicking and selecting "End Task". Notably, if I use the "Processes" tab and do the same, it actually seems to send a termination message to the processes instead, and the resulting behavior is not the same. So this is important if trying to reproduce the behavior by killing processes with Task Manager. |
The other child processes of Windows Terminal are the shells and console applications you spawn. By the way, when I said that we could check the exit code, I would not consider that an important "bug fix" or similar, but more like a nicety. OpenConsole is effectively the same as conhost and for both processes killing them is basically analogous to killing any shell or console applications they host. That's definitely way worse than not persisting the buffer contents, because that console application may have been a critical one. I'm sure they don't build rockets with Windows, but I wouldn't want to make assumptions what kind of applications people build with this OS. For the same reason, neither OpenConsole nor conhost are meant to ever crash and I think it's incredibly rare that they do. So, in that sense, killing OpenConsole as proof that we don't persist buffer contents correctly is IMO not fair. That's no different from killing Firefox or Chrome child processes, which also loses you all state, depending on when they got last persisted. However, killing Windows Terminal and it not having persisted any buffer contents whatsoever, that's IMO totally fair. Browsers do it, so we should probably do it too. We can fix that by regularly backing up the buffer contents as you suggested. I'm just not 100% sure when to do that, because the buffer serialization is not yet performance optimized and freezes the application for a noticeable amount of time when it runs with 10+ tabs. |
Sure. I was not accusing any component of working incorrectly. Just providing some insights into what I see actually happening. I appreciate hearing that backing up buffer contents more regularly is at least an agreeable idea. How and when is of course another matter that I have not the expertise to comment on. |
Once all applications that have received a `WM_ENDSESSION` message have returned from processing said message, windows will terminate all processes. This forces us to process the message synchronously. This meant that this issue was timing dependent. If Windows Terminal was quick at persisting buffers and you had some other application that was slow to shut down (e.g. Steam), you would never see this issue. Closes #17179 Closes #17250 ## Validation Steps Performed * Set up a lean Hyper-V VM for fast reboots * `Set-VMComPort <vm> 1 \\.pipe\\<pipe>` * Hook up WIL to write to COM1 * Add a ton of debug prints all over the place * Read COM output with Putty for hours * RTFM, and notice that the `WM_ENDSESSION` documentation states "the session can end any time after all applications have returned from processing this message" * Be very very sad ✅ * Fix it * Rebooting now shows on COM1 that persistence runs ✅ * Windows get restored after reboot ✅ (cherry picked from commit b439925) Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgSGCik Service-Version: 1.21
My understanding is that this shipped with v1.22. Today was the first time that my workstation performed Windows updates while having 1.22 installed, and Terminal successfully restored its state after logging back in, and also respected the change to show some of the restored history without scrolling up. Thanks! |
v1.21
I've now had a couple days where I've gotten a Windows Update, and came back to the Terminal not quite in the right state as before:
I have a theory that this is somehow related to us not handling
WM_ENDSESSION
post-PMv3 quite right, but that's a guess, not a root cause.The text was updated successfully, but these errors were encountered: