gpui(linux): Fix RefCell borrow panic when callbacks register new callbacks#49533
Merged
ConradIrwin merged 2 commits intozed-industries:mainfrom Feb 25, 2026
Conversation
mikayla-maki
approved these changes
Feb 18, 2026
Member
|
while I think this is a correct change, there’s a deeper problem here that every workspace is rebinding a window-level event. This should be hoisted up to the multiworkspace. |
…lbacks
On Linux (Wayland and X11), callbacks were invoked while the Callbacks
RefCell was still borrowed. If a callback tried to register a new
callback (e.g., on_window_should_close during workspace creation), it
would panic with "already borrowed".
The bug pattern was:
```rust
if let Some(ref mut fun) = self.callbacks.borrow_mut().input {
fun(input); // Panics if fun() tries to borrow_mut() callbacks
}
```
Fix by using take-call-restore pattern (matching macOS implementation):
```rust
let callback = self.callbacks.borrow_mut().input.take();
if let Some(mut fun) = callback {
let result = fun(input);
self.callbacks.borrow_mut().input = Some(fun);
}
```
Fixed locations:
- Wayland: handle_toplevel_decoration_event (2x), set_size_and_scale,
handle_input, set_focused, set_hovered, set_appearance
- X11: refresh, handle_input, set_active, set_hovered, set_appearance
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4e0238d to
f2897a3
Compare
tahayvr
pushed a commit
to tahayvr/zed
that referenced
this pull request
Mar 4, 2026
…lbacks (zed-industries#49533) ## Summary Fixes RefCell borrow panic on Linux (Wayland and X11) when callbacks try to register new callbacks. **Root cause:** Linux GPUI backends invoked callbacks while still holding a `RefCell` borrow on the `Callbacks` struct. If a callback tried to register a new callback (e.g., `on_window_should_close`), it would panic with "already borrowed: BorrowMutError". **Bug pattern:** ```rust // Callback runs while borrow is held - panics if callback borrows callbacks if let Some(ref mut fun) = self.callbacks.borrow_mut().input { fun(input); } Fix: Apply the take-call-restore pattern (already used in macOS backend): // Take callback out, release borrow, call, restore let callback = self.callbacks.borrow_mut().input.take(); if let Some(mut fun) = callback { let result = fun(input); self.callbacks.borrow_mut().input = Some(fun); } Changes - Wayland (window.rs): Fixed 6 callback invocations - X11 (window.rs): Fixed 4 callback invocations Test plan - cargo check -p gpui compiles successfully - Tested on Linux (Wayland) - no more RefCell panic Release Notes: - Fixed a crash on Linux when window callbacks attempted to register new callbacks Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
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.
Summary
Fixes RefCell borrow panic on Linux (Wayland and X11) when callbacks try to register new callbacks.
Root cause: Linux GPUI backends invoked callbacks while still holding a
RefCellborrow on theCallbacksstruct. If a callback tried to register a newcallback (e.g.,
on_window_should_close), it would panic with "already borrowed: BorrowMutError".Bug pattern: