Mysterious hang in Monarch::_getMostRecentPeasantID #15200

Closed
opened 2026-01-31 04:31:17 +00:00 by claunia · 5 comments
Owner

Originally created by @zadjii-msft on GitHub (Sep 13, 2021).

Originally assigned to: @zadjii-msft on GitHub.

version 1.12.2521.0.
Unsure how I got into this state. Probably

  • open windows 1, 2, 3. 1 is not the MRU window.
  • Close 2 and 3.
  • Try globalSummon the window. Terminal is in an infinite loop now inside Monarch::_getMostRecentPeasantID

but my repo's in the middle of a weird merge ATM so I can't verify on main

The symbols for this build don't include accurate source info, or at least my windbg is fucky. But what seems to be happening is _getMostRecentPeasantID is in the while (_mruPeasants.cbegin() + positionInList < _mruPeasants.cend()) loop. We're looking for ID=3, which we don't find in the list of peasants, so _getPeasant ends up returning null. We determine that we should have cleaned out that peasant ID from the MRU entries at that point, so we try again. However, we didn't. The MRU list still contains 3 at index 0, so we go looking for it again.

auto maybeThePeasant = peasantSearch == _peasants.end() ? nullptr : peasantSearch->second; in Monarch::_getPeasant ends up setting maybeThePeasant to null, which we then happily return (without cleaning up any MRU entries for it).

absolutely baseless list of possible commits to investigate:

I did not have the tray icon enabled.

Filing on myself so I don't lose this, but I don't think I'm getting anything more out of this debugger

There's no valuable logs other than a million Monarch_Collect_WasDead(Id=3, Desktop={guid})

Originally created by @zadjii-msft on GitHub (Sep 13, 2021). Originally assigned to: @zadjii-msft on GitHub. version **1.12.2521.0**. Unsure how I got into this state. Probably * open windows 1, 2, 3. 1 is not the MRU window. * Close 2 and 3. * Try `globalSummon` the window. Terminal is in an infinite loop now inside `Monarch::_getMostRecentPeasantID` but my repo's in the middle of a weird merge ATM so I can't verify on `main` The symbols for this build don't include accurate source info, or at least my windbg is fucky. But what seems to be happening is `_getMostRecentPeasantID` is in the `while (_mruPeasants.cbegin() + positionInList < _mruPeasants.cend())` loop. We're looking for ID=3, which we don't find in the list of peasants, so `_getPeasant` ends up returning null. We determine that we _should_ have cleaned out that peasant ID from the MRU entries at that point, so we try again. However, we didn't. The MRU list still contains 3 at index 0, so we go looking for it again. `auto maybeThePeasant = peasantSearch == _peasants.end() ? nullptr : peasantSearch->second;` in `Monarch::_getPeasant` ends up setting `maybeThePeasant` to `null`, which we then happily return (without cleaning up any MRU entries for it). absolutely baseless list of possible commits to investigate: * #11143 * #11043 * #10972 I did not have the tray icon enabled. Filing on myself so I don't lose this, but I don't think I'm getting anything more out of this debugger There's no valuable logs other than a million `Monarch_Collect_WasDead(Id=3, Desktop={guid})`
Author
Owner

@zadjii-msft commented on GitHub (Sep 13, 2021):

Note to self: those repro steps did repro this on 1.12.2521, so this has got to be fairly new. This should be easy enough to write a test for.

@zadjii-msft commented on GitHub (Sep 13, 2021): Note to self: those repro steps _did_ repro this on 1.12.2521, so this has got to be fairly new. This should be easy enough to write a test for.
Author
Owner

@Rosefield commented on GitHub (Sep 13, 2021):

Curious if this is would be fixed in https://github.com/microsoft/terminal/pull/11189. You of course collected the list of changes to the monarch I made, mostly around adding extra events on open/close of a peasant that can cause some churn. I didn't touch _getMostRecentPeasantId or _getPeasant so it might just be heap corruption from simultaneously removing peasants and iterating.

@Rosefield commented on GitHub (Sep 13, 2021): Curious if this is would be fixed in https://github.com/microsoft/terminal/pull/11189. You of course collected the list of changes to the monarch I made, mostly around adding extra events on open/close of a peasant that can cause some churn. I didn't touch `_getMostRecentPeasantId` or _`getPeasant` so it might just be heap corruption from simultaneously removing peasants and iterating.
Author
Owner

@Rosefield commented on GitHub (Sep 13, 2021):

Looking at the code again, the issue might be that in SignalClose I remove from the peasants map, but don't remove from _mruPeasants? Happy to fix this either on its own, or in the above PR with the other changes.

https://github.com/microsoft/terminal/blob/main/src/cascadia/Remoting/Monarch.cpp#L148

@Rosefield commented on GitHub (Sep 13, 2021): Looking at the code again, the issue might be that in SignalClose I remove from the peasants map, but don't remove from _mruPeasants? Happy to fix this either on its own, or in the above PR with the other changes. https://github.com/microsoft/terminal/blob/main/src/cascadia/Remoting/Monarch.cpp#L148
Author
Owner

@zadjii-msft commented on GitHub (Sep 13, 2021):

See, I knew I could file this, go to lunch, and come back to an answer 😝 Thanks for helping ID this. I'm okay combining this into #11189, so long as we make sure to add a test for this specific case. I just want to have as many tests on this stuff as possible.

Of course I type like a 2nd grader so while I was typing this, you filed the PR 😅. Doing it separately works too!

@zadjii-msft commented on GitHub (Sep 13, 2021): See, I knew I could file this, go to lunch, and come back to an answer 😝 Thanks for helping ID this. I'm okay combining this into #11189, so long as we make sure to add a test for this specific case. I just want to have as many tests on this stuff as possible. Of course I type like a 2nd grader so while I was typing this, you filed the PR 😅. Doing it separately works too!
Author
Owner

@ghost commented on GitHub (Oct 20, 2021):

:tada:This issue was addressed in #11217, which has now been successfully released as Windows Terminal Preview v1.12.2922.0.🎉

Handy links:

@ghost commented on GitHub (Oct 20, 2021): :tada:This issue was addressed in #11217, which has now been successfully released as `Windows Terminal Preview v1.12.2922.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v1.12.2922.0) * [Store Download](https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#15200