Skip to content

patches: winex11: don't wait forever for the pointer grab on focus ch… - #920

Closed
Syrupdesu wants to merge 1 commit into
GloriousEggroll:masterfrom
Syrupdesu:winex11-bound-pointer-grab-wait
Closed

Syrupdesu wants to merge 1 commit into
GloriousEggroll:masterfrom
Syrupdesu:winex11-bound-pointer-grab-wait

Conversation

@Syrupdesu

Copy link
Copy Markdown

…ange

wait_grab_pointer() retries XGrabPointer() every 10ms until it succeeds. That never happens when the grab is held by another thread of the same process that is blocked in a synchronous SendMessage() to the thread changing focus: the sender cannot release the grab before its message is processed, and the receiver cannot process the message before the grab is released.

Bound the wait to one second so that the pending message can be processed and the grab released. The patch has the reproduction details.

…ange

wait_grab_pointer() retries XGrabPointer() every 10ms until it succeeds.
That never happens when the grab is held by another thread of the same
process that is blocked in a synchronous SendMessage() to the thread
changing focus: the sender cannot release the grab before its message is
processed, and the receiver cannot process the message before the grab is
released.

Bound the wait to one second so that the pending message can be processed
and the grab released. The patch has the reproduction details.
@GloriousEggroll

Copy link
Copy Markdown
Owner

Thanks for tracking this down, the deadlock is real: the grab can be held by another thread of the same process (capture in menu/move-size mode, or cursor clipping) that is blocked in a SendMessage to the thread waiting in wait_grab_pointer().

I'd rather not cap the wait at one second though. The wait exists so WM_ACTIVATE is delayed while the window manager is moving or resizing the window (42c2128), and a title bar drag regularly takes longer than a second, so the cap brings back the stale-clip-rect problem that commit fixed.

Could you instead stop waiting when the thread has a sent message pending? Something like:

if (HIWORD( NtUserGetQueueStatus( QS_SENDMESSAGE ) )) break;

before the NtDelayExecution(). That breaks the deadlock on the first retry instead of after a second, and leaves the WM move/resize case alone. NtUserGetQueueStatus() calls back into ProcessEvents, but nested event processing is already disabled while an event is being handled, so it's safe from there. If that fixes Endfield for you I'm happy to merge it.

@GloriousEggroll

Copy link
Copy Markdown
Owner

Thanks for tracking this down, merged! The deadlock is real: winex11 itself can hold the grab from another thread (capture in menu/move-size mode, or cursor clipping) while that thread is blocked in a SendMessage to the one waiting in wait_grab_pointer().

I changed one thing in a follow-up commit: instead of giving up after one second, the wait now stops as soon as the thread has a sent message pending (HIWORD(NtUserGetQueueStatus(QS_SENDMESSAGE))). The wait exists to delay WM_ACTIVATE while the window manager moves or resizes the window (42c2128), and a title bar drag often takes longer than a second, so a fixed cap would bring that problem back. This way the deadlock breaks on the first retry and window drags still wait. NtUserGetQueueStatus() calls back into ProcessEvents, but nested event processing is disabled while an event is being handled, so it's safe there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants