Skip to content

Do proper wayland teardown cleaning up listeners and fds#2066

Open
3v1n0 wants to merge 8 commits into
ValveSoftware:masterfrom
3v1n0:disconnect-from-signals
Open

Do proper wayland teardown cleaning up listeners and fds#2066
3v1n0 wants to merge 8 commits into
ValveSoftware:masterfrom
3v1n0:disconnect-from-signals

Conversation

@3v1n0
Copy link
Copy Markdown

@3v1n0 3v1n0 commented Jan 21, 2026

In debian we're already using wlroots-0.19, but with it every time a client window is closed or when gamescope itself is closed, we crash with an assertion error.

So remove event listeners (helping #1990) and close the drm FD, ensuring that the page-flip thread is completed.

See commits for details.

@3v1n0 3v1n0 mentioned this pull request Jan 21, 2026
1 task
@3v1n0 3v1n0 changed the title Do proper wayland teardown cleanning up listeners and fds Do proper wayland teardown cleaning up listeners and fds Jan 21, 2026
@3v1n0 3v1n0 force-pushed the disconnect-from-signals branch from ed8b88b to 863aaca Compare January 21, 2026 04:21
Comment thread src/wlserver.cpp Outdated
Comment thread src/Backends/DRMBackend.cpp Outdated
Comment thread src/Backends/DRMBackend.cpp Outdated
Comment thread src/Backends/DRMBackend.cpp Outdated
Comment thread src/Backends/DRMBackend.cpp Outdated
@emersion
Copy link
Copy Markdown
Collaborator

@3v1n0, any chance you'd get some time to have a look at this PR?

@awsms
Copy link
Copy Markdown

awsms commented Apr 3, 2026

ping @3v1n0

@k0tran
Copy link
Copy Markdown

k0tran commented Apr 8, 2026

Friendly ping @3v1n0

ALT Linux is on the way to drop libwlroots 0.18 from testing (sisyphus) repo. Was able to build gamescope with patches but would really appreciate proper upstream support.

@MrMeshok
Copy link
Copy Markdown

MrMeshok commented Apr 8, 2026

Marco probably busy with soon to be released Ubuntu 26.04

@emersion Could gamescope skip 0.19 and jump straight to 0.20? I tried building Debian package with libwlroots 0.20 (with patches from this PR) and in my quick testing it was ok

@3v1n0 3v1n0 force-pushed the disconnect-from-signals branch from 863aaca to 0f0ddc0 Compare May 22, 2026 19:15
@3v1n0
Copy link
Copy Markdown
Author

3v1n0 commented May 23, 2026

Sorry for the delay, I think I handled the main things, let me know

3v1n0 added 8 commits May 23, 2026 14:16
If we do not do this newer wlroots would rightly assert every time that
a surface gets closed with:

  gamescope: types/wlr_compositor.c:734:
     surface_handle_resource_destroy:
       Assertion `wl_list_empty(&surface->events.commit.listener_list)'
       failed.

  gamescope: types/wlr_compositor.c:737:
    surface_handle_resource_destroy:
      Assertion `wl_list_empty(&surface->events.destroy.listener_list)'
      failed.
Prevents:
  gamescope: xwayland/server.c:462: wlr_xwayland_server_destroy:
    Assertion `wl_list_empty(&server->events.ready.listener_list)' failed
Starting from wlroots 0.19 all these would trigger assertion errors
Destroy the event signals handlers on shutdown
Avoid heap-allocating the listener with new; embed it directly in the
wlserver_t struct instead.
We were not closing the KMS session on destruction since the DRM FD
might be still being polled by the page-flip thread.

Handle this gracefully now by:
 - Create a pipe
 - Pass the pipe to the thread
 - Make the thread to repeatedly and atomically check if it should exit

When we're about to finish the drm backend:
 - Mark the thread as thread as completed
 - Close the pipe write end to signal the thread that we're done
 - Join the thread to wait its completion
 - Finally close KMS on wayland side and unset the drm fd

This allows to finally close all the remaining resources or signal
connections that we created on wayland side
@3v1n0 3v1n0 force-pushed the disconnect-from-signals branch from 0f0ddc0 to baf810e Compare May 23, 2026 12:17
Comment thread src/wlserver.cpp
if ( wlserver.wlr.session )
{
wl_list_remove( &wlserver.session_active.link );
wlr_session_destroy( wlserver.wlr.session );
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This commit causes a SIGSEGV on exit for me in libseat.

Do we really need it? The session will destroy itself automatically with wl_display_destroy().

@emersion
Copy link
Copy Markdown
Collaborator

With the commit mentioned above reverted, this branch works well for me!

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.

5 participants