[PR #10549] [MERGED] Fix racy access to _tsfTryRedrawCanvas in TermControl #28104

Open
opened 2026-01-31 09:26:22 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10549
Author: @lhecker
Created: 7/2/2021
Status: Merged
Merged: 7/6/2021
Merged by: @undefined

Base: mainHead: dev/lhecker/exit-crash-fix


📝 Commits (3)

  • 1900fad Fix racy access to _tsfTryRedrawCanvas in TermControl
  • ca63317 Fix formatting check
  • 52ae1f1 Fix _closing not being set

📊 Changes

2 files changed (+65 additions, -75 deletions)

View changed files

📝 src/cascadia/TerminalControl/TermControl.cpp (+55 -72)
📝 src/cascadia/TerminalControl/TermControl.h (+10 -3)

📄 Description

Previously TermControl::Close destroyed all ThrottledFuncs to ensure they're not scheduling any callbacks on the UI thread, as the call to Close signals the point at which the TermControl isn't part of the UI thread anymore. _CursorPositionChanged tried to prevent access to the potentially deallocated _tsfTryRedrawCanvas by checking the std::shared_ptr for nullability, but since the deallocation happens on the UI thread and the nullability check on a background thread, this check introduced a race condition.

This commit solves the issue by not deallocating any ThrottledFuncs anymore and instead checking the _closing flag inside the ThrottledFunc callback on the UI thread.

Additionally this commit cleans up some antipatterns around the use of std::optional.

PR Checklist

Validation Steps Performed

  • Opening and closing tabs doesn't crash ✔️
  • Printing long text doesn't crash ✔️
  • Manual scrolling doesn't crash ✔️
  • ^G / the audible bell doesn't crash ✔️

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/10549 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 7/2/2021 **Status:** ✅ Merged **Merged:** 7/6/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/lhecker/exit-crash-fix` --- ### 📝 Commits (3) - [`1900fad`](https://github.com/microsoft/terminal/commit/1900fad802899287550bd43ecaa5bad3b22de215) Fix racy access to _tsfTryRedrawCanvas in TermControl - [`ca63317`](https://github.com/microsoft/terminal/commit/ca63317bc1b9c9b623585ef800d3464c60988adf) Fix formatting check - [`52ae1f1`](https://github.com/microsoft/terminal/commit/52ae1f1fd1e72b627b4ae675c5f24dbdecd86208) Fix _closing not being set ### 📊 Changes **2 files changed** (+65 additions, -75 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+55 -72) 📝 `src/cascadia/TerminalControl/TermControl.h` (+10 -3) </details> ### 📄 Description Previously `TermControl::Close` destroyed all `ThrottledFunc`s to ensure they're not scheduling any callbacks on the UI thread, as the call to `Close` signals the point at which the `TermControl` isn't part of the UI thread anymore. `_CursorPositionChanged` tried to prevent access to the potentially deallocated `_tsfTryRedrawCanvas` by checking the `std::shared_ptr` for nullability, but since the deallocation happens on the UI thread and the nullability check on a background thread, this check introduced a race condition. This commit solves the issue by not deallocating any `ThrottledFunc`s anymore and instead checking the `_closing` flag inside the `ThrottledFunc` callback on the UI thread. Additionally this commit cleans up some antipatterns around the use of `std::optional`. ## PR Checklist * [x] Closes #10479 * [x] Closes #10302 ## Validation Steps Performed * Opening and closing tabs doesn't crash ✔️ * Printing long text doesn't crash ✔️ * Manual scrolling doesn't crash ✔️ * ^G / the audible bell doesn't crash ✔️ --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:26:22 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28104