Repository navigation
Description
Apologies if this is a dupe... I searched and found related but not exact reports.
About once per week or two, I wake up and find that my Windows Terminal app (installed from Windows Store) has closed. I re-open it and re-launch my various tabs and processes. The computer didn't restart because my other apps are still in their previous state, but Windows Terminal is just closed. Maybe it crashed? Maybe Windows force-closed it (that's my guess)?
But often, one of these process launches will fail because the port I'm trying to bind to is still in use. This clues me in to look at my open processes list (ps ax), and I'm sometimes horrified to see that I have a dozen or more open bash processes (plus any child processes they may have been running), just sitting there all orphaned. I'm sort of amazed that they are still able to run without being attached to any terminals -- but more annoyed by it (especially given the battery drain I experience). I've been able to see a noticeable decrease in battery life, as much as 1-2 hours from a full charge usage in the cases where a bunch of those background processes are just sitting around orphaned.
Then I have to manually go through and sudo kill -9 all of those.
When I manually closed Terminal, it kills all my open sessions. But somehow, someway, this occasional closing of terminal that occurs (on purpose or via crash, I dunno) orphans them somewhat more "predictably" (as in, happens pretty much every time).
I found #3915, which could be the explanation, and there was one comment in that now-locked thread that mentioned some orphan processes... but I'm filing this issue specifically because it seems quite a defect that Terminal can somehow close (for any reason) without killing all its child processes. I can't come up with any example where that should be possible. This seems like a significant defect that should be addressed.
Activity
zadjii-msft commentedon Nov 1, 2021
(Dunno how this one missed the triage queue...)
That's definitely not what we'd want to have happen. We've got unfortunately very little say in the matter when we get force-updated by the store, (#3915, #6726, etc), but it's troubling that the child processes are orphaned instead of killed.
Does this consistently happen with the children of one particular type of shell? For example, does this always happen with WSL processes, or does it happen with children running in
powershell.exetoo?I just want to try and get a complete picture here before I reach our to our store/deployment teams.
That would seem to suggest that this isn't due to the Store updating it. That could have been an anomaly, we could have updated a couple times in the time leading up to this original post, idk. If this is still happening with some frequency, can you try following the steps in this post to set up automatic crash dumps? If that works, then you should be able to automatically get a
.dmpof the terminal when it crashes. Then, can you zip that dump up and send it to us, so we can investigate? Thanks!getify commentedon Nov 1, 2021
Yeah, I don't think it was the Store updating the app, at least not that I could directly link it to. I don't think I have auto-updating enabled on my Windows... I believe I have to approve updates and intentionally let them run.
I generally leave my computer on 24/7, and what I was observing was just when I came back to it in the morning, the Terminal app was closed (but other windows were still open). Occasionally, I would see that the computer had re-started itself, and the terminal didn't re-open, but in those cases since the computer re-started, I (obviously) didn't see any orphaned processes in those cases.
In the case of the app itself closing without a computer restart, THAT is where the orphaned processes would build up. And I would only discover that if/when I would re-launch the Terminal and then try to run a process that, for example, binds to an IP address/port, and would be alerted that the IP/port was already bound (even though I just re-opened the Terminal). Another symptom was that if I would run
ps ax, I would see dozens of processes still running that I would have expected had been killed weeks earlier (from previous closing of the app).I only use Terminal with WSL (debian), so I can't say if this was happening for other types of terminal sessions.
All that said, I don't think I've had the Terminal crash on me since about June or maybe July.
getify commentedon Nov 1, 2021
I should add, I believe there were times when I intentionally closed the whole Terminal app (without individually killing running processes in each open Terminal tab), and I believe there were times when some of those processes were cleanly killed, and other times where those processes were orphaned.
zadjii-msft commentedon Nov 1, 2021
Huh.
Well that's a good thing!
I'm gonna leave this open for another week or so, esp. since I just redirected #11651 here. This might be a weird interaction with Terminal+Store+WSL, where the Store kills the terminal&conhost in such a way that WSL doesn't realize it and doesn't shut itself down like it would if you closed the console window normally. Craig Loewen (@craigloewen-msft) You know if you guys have heard of anything like this on the WSL side?
j4james commentedon Nov 1, 2021
Note that we've also had reports of orphaned processes in issue #3915 (comment) and issue #7345.
l10nelw commentedon Nov 2, 2021
chrystalis commentedon Nov 2, 2021
I do believe that the store updates are causing this. It is very unpleasant to come back to my machine in the morning and find my terminals gone and a bunch of orphaned WSL1 (Ubuntu 18.04) and WSL2 (Ubuntu 20.04) processes.
I just found #6726 and have subsequently turned off store application auto-updates, though I don't recall ever having turned it on.
From the AppXDeployment-Server event log - apparently it waited 2.5 days before unceremoniously closing my terminals, but I did not know since it never provided any actual notification in the UI:
Same thing happened a couple of weeks ago:
47 remaining items
zadjii-msft commentedon Aug 2, 2022
There are plenty of other threads on that specific topic - I'm gonna pretty explicitly keep this thread on-topic to the orphaning processes issue. See See #6726 (comment) for more. (thanks for the link James Holderness (@j4james))
ukdocCT commentedon Aug 18, 2022
Following on from this: #9914 (comment)
If it gracefully closes (after the initial notification), and then (if) closes all the sessions, or gets forced closed (after the 30s) then that is only slightly better than the current situation. Yes we don't have any orphaned consoles, but it still closes out all our consoles meaning we loose work.
As someone that regularly has a lot of different consoles open doing different things this is just a nightmare. Regularly i will leave something running in a powershell or WSL session to come in the following morning and have no idea where my scripts got to as i have no way of reattaching to the consoles.
As others have said even uninstalling from the store and installing the msixbundle directly still gets picked up by the store and auto updated.
On my home machine i only ever installed via the appxbundle and that never auto-updates and allows me to perform a controlled updated when i have time, but that may be because i dont auto-update my store apps.
Hopefully there will be a way of convincing the store to give up its claim to the manually install msixbundle.
ricklove commentedon Oct 6, 2022
This happens to me about once a month. I wake up in the morning and windows terminal is closed. This is usually about 5 windows with 2-5 tabs each so it's not a great experience.
I actually like the fact that it doesn't kill the process (well if I had a long running process doing some work anyway), but it would be great if it could reconnect each window and tab. (vscode does this well)
Since windows has been begging for an update, I guess it's time to restart now.
getify commentedon Oct 6, 2022
FYI:
I recently found this tool reptyr, which re-parents a process to a current tty. YMMV, but it may be helpful as a temporary work-around if you have shell orphaned processes that you'd like to reclaim, and perhaps either shutdown cleanly or just continue to monitor until it completes.
I've tested it on current tty sessions and processes, but I plan to test it on orphaned processes the next time my shell dies thanks to windows (store).
ukdocCT commentedon Oct 7, 2022
unfortunately, i think that will only reattach linux sessions once inside the linux session - similar to tmux etc, i dont think that will work in Windows with reattaching WSL, batch or similar.
zadjii-msft commentedon May 3, 2023
Hey so loop back on the original root issue tracked in this thread: "CLI processes are orphaned when the Terminal is updated by the store" - has anyone seen that in the 1.15->1.16+ updates?
In 1.15, we merged #13614, which should have fixed this for the subsequent updates to 1.16 / 1.17. I believe there might have also been some changes to the conpty handling in 1.17 that should have made this more robust.
If it's still happening, then we'll have to go back to the drawing board on finding a setup to repro that consistently.
getify commentedon May 3, 2023
Here's what I'm still seeing regularly:
an update closes the whole app, losing all my tabs -- this super sucks, and I still cannot understand how anyone believes this is the right thing for a long-lived app to be able to forcibly close on update with no restoration. almost no other app (browser, editor, etc) could get away with that.
on occasion (maybe once per month), it seems like an update fails to close my full terminal session, but what it does instead is MUCH worse... it basically crashes the WSL process... I see the CPU on my system start spiking to 60%+ usage, fans spin, and the main process is like "virtual mem" or something. The WSL is then completely unusable, and I cannot even restart the terminal to connect to a new WSL session. I also can't close the process since it's some protected system process. the only fix is to restart the computer.
Also, I know you've triaged this thread as if "forced closed" is somehow a separate issue from my original OP of orphaned processes. I am persisting in linking the two, because they are two sides of the same problem.
I think it's mishandling of my report to say "great, we no longer have orphaned processes" because that was just one smaller aspect of the larger problem. What I meant when I filed this was not ONLY the orphaning, but the fact that force closes ARE THE PROBLEM.
In other words, the bug of orphaned processes is a symptom, not a root cause.
It's not very much comfort that one symptom might have been fixed but the deeper problem is just ignored as off-topic.
ukdocCT commentedon May 3, 2023
I believe this is a consequence of it being a UWP app which for the most part i believe are designed to be suspended and restarted without loosing context and data.
I have tried to untangle my install from the store - totally unsuccessfully, so have now turned off auto-updates in the store so that i can control when the updates occur and not loose the dozen or so consoles i have open on my daily machine.
zadjii-msft commentedon May 3, 2023
I like to triage issues as separate root causes. In this case, this report covered two problems:
Now, we already have another thread with a very long discussion on the first topic, over in #6726. If that was the only point being made in this thread, I would have long ago closed this as a duplicate.
The orphaning of processes described in this thread is a wholly unique issue, so I choose instead to focus this thread on that particular effect. We can try to remedy that issue independently of the (much harder to resolve) first issue.
The Terminal is not a UWP app. That's kind of an outdated notion in 2023. The Terminal is a packaged, full-trust, win32 application that uses UWP XAML, via XAML Islands is the most correct way to describe ~ w h a t ~ the terminal is. In this case, the "packaged" element is the most relevant, because it's the way that the Store interacts with packaged applications that results in what you're describing.
I suspect (using only psychic debugging) that the "an update crashes WSL and spins a CPU" issue is also a side effect of #6726 / "the store kills apps for updates". I'm not a WSL engineer, so I have no idea how to investigate that further. I'd recommend filing this on https://github.com/microsoft/WSL. My psychic debugging theory is that this is also due to the Store killing the WSL package, to update WSL, and they'll need a similar fix as to #6726. (this is something we've discussed offline with them)
zadjii-msft commentedon Feb 7, 2024
Okay so
<uap17:UpdateWhileInUse>defer</uap17:UpdateWhileInUse>1 I think should have fixed this, at least on the Terminal side, and for Windows 112. That should stop the store from killing us for updates.Now, if there's other scenarios where the Terminal crashes and that leaves orphaned processes: we should probably file a new thread to track that at this point. This thread has pretty heavily drilled in on "terminal gets force killed and that orphans things", and with that fixed, I'd like to track other root causes separately.
Thanks all!
Footnotes
Which we added in Defer package updates while the Terminal is running #16250, v1.20.10293.0 and v1.19.3172.0 ↩
Alas, that feature requires OS-side support, so it's not something we can bring with us downlevel. ↩