gpui: Fix RefCell panic in thermal/keyboard state callbacks#49187
Merged
morgankrey merged 1 commit intomainfrom Feb 14, 2026
Merged
gpui: Fix RefCell panic in thermal/keyboard state callbacks#49187morgankrey merged 1 commit intomainfrom
morgankrey merged 1 commit intomainfrom
Conversation
Use try_borrow_mut() instead of borrow_mut() in on_thermal_state_change and on_keyboard_layout_change callbacks. These callbacks can be invoked asynchronously by macOS while the app RefCell is already borrowed during an update cycle, causing a panic. Fixes Sentry ZED-4WM. Closes #49181. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
b5bf865 to
3238876
Compare
morgankrey
added a commit
that referenced
this pull request
Feb 14, 2026
Follow-up to #49187. Instead of silently skipping updates when try_borrow_mut fails, defer the update by spawning it on the foreground executor. This ensures the state change is eventually processed after the current borrow completes. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
morgankrey
added a commit
that referenced
this pull request
Feb 14, 2026
Follow-up to #49187. Always spawn the update on the foreground executor instead of borrowing the app directly in the callback. This avoids RefCell panics when macOS fires these callbacks asynchronously while the app is already borrowed. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
morgankrey
added a commit
that referenced
this pull request
Feb 14, 2026
Follow-up to #49187. Instead of silently skipping updates when `try_borrow_mut` fails, this PR defers the update by spawning it on the foreground executor. This ensures the state change is eventually processed after the current borrow completes. Release Notes: - N/A
marcocondrache
added a commit
to marcocondrache/zed
that referenced
this pull request
Feb 16, 2026
bennetbo
pushed a commit
that referenced
this pull request
Feb 16, 2026
…ed" (#49251) Reverts #49189 Reverts #49187 #49189 introduces a panic (#49189 (comment), #49181 (comment)) #49187 It's wrong since it leads to missing updates The original crash should be fixed with #49086 cc: @bennetbo Release Notes: - N/A
rtfeldman
pushed a commit
that referenced
this pull request
Feb 17, 2026
The `on_thermal_state_change` and `on_keyboard_layout_change` callbacks in `App::new_app()` called `borrow_mut()` unconditionally. These callbacks are invoked asynchronously by macOS via dispatch queues when the system's thermal or keyboard state changes, which can happen while the app's RefCell is already borrowed during an update cycle, causing a panic. This change uses `try_borrow_mut()` instead. If the borrow fails (because the app is already borrowed), the callback silently skips the update - the state can be queried on the next frame. Fixes [ZED-4WM](https://zed-dev.sentry.io/issues/ZED-4WM) Closes #49181 Release Notes: - Fixed a crash on macOS caused by thermal or keyboard layout state changes occurring during UI updates.
rtfeldman
pushed a commit
that referenced
this pull request
Feb 17, 2026
Follow-up to #49187. Instead of silently skipping updates when `try_borrow_mut` fails, this PR defers the update by spawning it on the foreground executor. This ensures the state change is eventually processed after the current borrow completes. Release Notes: - N/A
rtfeldman
pushed a commit
that referenced
this pull request
Feb 17, 2026
…ed" (#49251) Reverts #49189 Reverts #49187 #49189 introduces a panic (#49189 (comment), #49181 (comment)) #49187 It's wrong since it leads to missing updates The original crash should be fixed with #49086 cc: @bennetbo Release Notes: - N/A
Caio-Ze
pushed a commit
to Caio-Ze/postprod-ide
that referenced
this pull request
Feb 21, 2026
…stries#49187) The `on_thermal_state_change` and `on_keyboard_layout_change` callbacks in `App::new_app()` called `borrow_mut()` unconditionally. These callbacks are invoked asynchronously by macOS via dispatch queues when the system's thermal or keyboard state changes, which can happen while the app's RefCell is already borrowed during an update cycle, causing a panic. This change uses `try_borrow_mut()` instead. If the borrow fails (because the app is already borrowed), the callback silently skips the update - the state can be queried on the next frame. Fixes [ZED-4WM](https://zed-dev.sentry.io/issues/ZED-4WM) Closes zed-industries#49181 Release Notes: - Fixed a crash on macOS caused by thermal or keyboard layout state changes occurring during UI updates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
on_thermal_state_changeandon_keyboard_layout_changecallbacks inApp::new_app()calledborrow_mut()unconditionally. These callbacks are invoked asynchronously by macOS via dispatch queues when the system's thermal or keyboard state changes, which can happen while the app's RefCell is already borrowed during an update cycle, causing a panic.This change uses
try_borrow_mut()instead. If the borrow fails (because the app is already borrowed), the callback silently skips the update - the state can be queried on the next frame.Fixes ZED-4WM
Closes #49181
Release Notes: