Skip to content

gpui: Fix send_file_drop_event holding mutex during event callback#50173

Merged
MrSubidubi merged 1 commit intozed-industries:mainfrom
Albab-Hasan:fix/gpui-file-drop-mutex
Feb 26, 2026
Merged

gpui: Fix send_file_drop_event holding mutex during event callback#50173
MrSubidubi merged 1 commit intozed-industries:mainfrom
Albab-Hasan:fix/gpui-file-drop-mutex

Conversation

@Albab-Hasan
Copy link
Contributor

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

`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 re-enter `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).
however, `parking_lot::Mutex` is not reentrant, so any future platform call
added inside a file-drop 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 re-acquiring the lock to restore the callback and update state.
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 26, 2026
@Albab-Hasan
Copy link
Contributor Author

@MrSubidubi hey, can you check this out? only if u have some free time

@maxdeviant maxdeviant changed the title gpui: fix send_file_drop_event holding mutex during event callback gpui: Fix send_file_drop_event holding mutex during event callback Feb 26, 2026
@MrSubidubi MrSubidubi changed the title gpui: Fix send_file_drop_event holding mutex during event callback gpui: Fix send_file_drop_event holding mutex during event callback Feb 26, 2026
Copy link
Member

@MrSubidubi MrSubidubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch and follow-up, thank you!

@MrSubidubi MrSubidubi self-assigned this Feb 26, 2026
@MrSubidubi MrSubidubi enabled auto-merge (squash) February 26, 2026 16:48
@Albab-Hasan
Copy link
Contributor Author

@MrSubidubi i was honestly worried that this wont be worth reviewing or merging

@MrSubidubi
Copy link
Member

Stuff like this is totally fine and you also add good explanations, which helps with reviewing. No worries!

@Albab-Hasan
Copy link
Contributor Author

@MrSubidubi thats really good to hear, because i pinned about a dozen more of these but didnt have to confidence to push them.

also if you dont mind me asking are you in charge of reviewing everything macos related?

@MrSubidubi MrSubidubi merged commit dd9efd9 into zed-industries:main Feb 26, 2026
31 checks passed
@MrSubidubi
Copy link
Member

also if you dont mind me asking are you in charge of reviewing everything macos related?

Nope, not at all. You are free to push them (maybe not all at one, though 😅 ) and we'll eventually take a look. It can take some time (and no need to ping, we'll see what's coming in), sometimes longer than we'd like to, but eventually we will get back to you 🙂

@Albab-Hasan
Copy link
Contributor Author

@MrSubidubi ok. im genuinely sorry for the bother tho. I'll make sure to let u guys do your thing. the thing is i need all the oss merges i can get to pass 10th grade lol

@MrSubidubi
Copy link
Member

You are free to send them, as mentioned above, given that they also aligh with https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md. So no need to hesistate, probably just don't send 5 PRs at one 😅

rtfeldman pushed a commit that referenced this pull request Feb 27, 2026
…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
tahayvr pushed a commit to tahayvr/zed that referenced this pull request Mar 4, 2026
…ed-industries#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
naaiyy added a commit to Glass-HQ/gpui that referenced this pull request Mar 10, 2026
Port of upstream zed-industries/zed#50173. Releases the
MacWindowState lock before invoking the event callback, matching the
take/drop/callback pattern used by every other dispatch site in
window.rs.
naaiyy added a commit to Glass-HQ/Glass that referenced this pull request Mar 10, 2026
…ed-industries#50173)

Upstream commit dd9efd9 applied to the separate GPUI repository.
No changes needed in Glass itself.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants