Skip to content

SDL_WaitEventTimeout can block indefinitely on Wayland #15380

@fstanis

Description

@fstanis

I was debugging some code in FreeRDP that seems to sometimes have huge input delays and found out that SDL_WaitEventTimeout seems to be the culprit. I have something that's similar to this loop (from FreeRDP):

while (!sdl->shallAbort())
    {
    SDL_Event windowEvent = {};
    while (!sdl->shallAbort() && SDL_WaitEventTimeout(nullptr, 1000))
    {
            ...
    }
}

It seems to happen when the cursor changes, specifically there seems to be a race condition in Wayland_CursorStateSetCursor.

  1. The main thread enters Wayland_WaitEventTimeout, flushes, and blocks in poll on the display fd.
  2. A cursor change (e.g., from SDL_SetCursor called from another thread, or from an SDL main-thread callback) queues Wayland requests in the write buffer.
  3. Neither Wayland_ShowCursor() nor Wayland_CursorStateSetCursor calls wl_display_flush or Wayland_SendWakeupEvent.
  4. The cursor thread is also blocked with infinite timeout (timeoutNS is -1 initially) on the same fd.
  5. The compositor never receives the cursor requests, so it sends no events and poll never returns.

Probably the simplest thing to do would be to flush cursor events in Wayland_CursorStateSetCursor or alternatively to call Wayland_SendWakeupEvent to avoid a deadlock.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions