Race condition during AppLogic::ReloadSettings and all reads of _settings #22531

Closed
opened 2026-01-31 08:15:59 +00:00 by claunia · 0 comments
Owner

Originally created by @lhecker on GitHub (Nov 11, 2024).

Windows Terminal version

All of them

Windows build number

No response

Other Software

No response

Steps to reproduce

Reduce startup cost and make Windows Terminal launch faster.

Expected Behavior

No response

Actual Behavior

Windows Terminal will randomly crash because now that it starts a lot faster (relatively speaking) the main- and window-thread(s) will call ReloadSettings() concurrently.

Additionally, we swap out the _settings member on the main thread while window threads may currently be reading from it. This is problematic because after optimizations the pointer to _settings may be cached in a register or on the stack and so we may end up reading from a settings instance that has since been deleted.

Sounds like a rare occurrence, but with just the right timing (which I now have), this crashes the app 99% of the time during startup. I suspect it also happens on main, but simply less often.

Originally created by @lhecker on GitHub (Nov 11, 2024). ### Windows Terminal version All of them ### Windows build number _No response_ ### Other Software _No response_ ### Steps to reproduce Reduce startup cost and make Windows Terminal launch faster. ### Expected Behavior _No response_ ### Actual Behavior Windows Terminal will randomly crash because now that it starts a lot faster (relatively speaking) the main- and window-thread(s) will call `ReloadSettings()` concurrently. Additionally, we swap out the `_settings` member on the main thread while window threads may currently be reading from it. This is problematic because after optimizations the pointer to `_settings` may be cached in a register or on the stack and so we may end up reading from a settings instance that has since been deleted. Sounds like a rare occurrence, but with just the right timing (which I now have), this crashes the app 99% of the time during startup. I suspect it also happens on main, but simply less often.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22531