From cc78b536bf0e5fdebd9fdd6e1acf0ad2df114fa6 Mon Sep 17 00:00:00 2001 From: Albab Hasan <155961300+Albab-Hasan@users.noreply.github.com> Date: Thu, 26 Feb 2026 22:58:40 +0600 Subject: [PATCH] gpui: Fix `send_file_drop_event` holding mutex during event callback (#50173) `send_file_drop_event` was the only event dispatch site in window.rs that called the event callback while still holding the `MacWindowState` mutex. every other callback site in the file uses the established `take() / drop(lock) / callback()` pattern which releases the lock before invoking user code. this is a latent code quality issue: no deadlock occurs today because the current file-drop callback chain does not reenter `MacWindowState`'s mutex (`Window::mouse_position()` returns a cached field `Window::refresh()` only marks a dirty flag and `cx.activate()` uses a separate `MacPlatform` mutex). but `parking_lot::Mutex` is not entering so any future platform call added inside a filedrop handler would deadlock immediately and silently. the fix brings `send_file_drop_event` in line with the rest of the file by taking the callback out of the state dropping the lock invoking the callback then reacquiring the lock to restore the callback and update state. Release Notes: - N/A --- crates/gpui_macos/src/window.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/crates/gpui_macos/src/window.rs b/crates/gpui_macos/src/window.rs index 0d4edc28e8..87cd5ee21d 100644 --- a/crates/gpui_macos/src/window.rs +++ b/crates/gpui_macos/src/window.rs @@ -2551,19 +2551,20 @@ fn send_file_drop_event( window_state: Arc>, file_drop_event: FileDropEvent, ) -> bool { - let mut window_state = window_state.lock(); - let window_event_callback = window_state.event_callback.as_mut(); - if let Some(callback) = window_event_callback { - let external_files_dragged = match file_drop_event { - FileDropEvent::Entered { .. } => Some(true), - FileDropEvent::Exited => Some(false), - _ => None, - }; + let external_files_dragged = match file_drop_event { + FileDropEvent::Entered { .. } => Some(true), + FileDropEvent::Exited => Some(false), + _ => None, + }; + let mut lock = window_state.lock(); + if let Some(mut callback) = lock.event_callback.take() { + drop(lock); callback(PlatformInput::FileDrop(file_drop_event)); - + let mut lock = window_state.lock(); + lock.event_callback = Some(callback); if let Some(external_files_dragged) = external_files_dragged { - window_state.external_files_dragged = external_files_dragged; + lock.external_files_dragged = external_files_dragged; } true } else {