Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

xdg-surface: handle inert toplevels and popups in when committing #2454

Merged
merged 1 commit into from
Nov 8, 2020

Conversation

ammen99
Copy link
Member

@ammen99 ammen99 commented Oct 27, 2020

This is an attempt to Fixes #2432
@dkondor please test

@dkondor
Copy link
Contributor

dkondor commented Oct 28, 2020

Just tested this (this branch applied on top of latest wlroots master + wayfire master).

The crash after dismissing the dialog is gone, but there is a new crash when closing a toplevel that used to have a dialog.

This happens in my simplified example: https://github.com/dkondor/wlroots/blob/issue-2432/issue-2432/wlr-crasher-2.c

To reproduce, close the blue dialog either by clicking on it or by activating another app. After that, when the main toplevel is closed (clicking on it or even Ctrl-C from terminal), wayfire crashes.

I cannot test my original issues with cairo-dock, since trying to start it already crashes wayfire with this patch.

@dkondor
Copy link
Contributor

dkondor commented Oct 28, 2020

Stackrace:

EE 28-10-20 11:56:08.144 - [src/main.cpp:233] Fatal error: Segmentation fault
EE 28-10-20 11:56:08.183 - #1  signal_handler(int) ../src/main.cpp:234
EE 28-10-20 11:56:08.361 - #2  killpg ??:?
EE 28-10-20 11:56:08.370 - #3  wl_list_remove /home/dkondor/program/wayland/src/wayland-util.c:55
EE 28-10-20 11:56:08.383 - #4  reset_xdg_surface ../types/xdg_shell/wlr_xdg_surface.c:513
EE 28-10-20 11:56:08.397 - #5  destroy_xdg_surface ../types/xdg_shell/wlr_xdg_surface.c:517
EE 28-10-20 11:56:08.410 - #6  xdg_surface_handle_resource_destroy ../types/xdg_shell/wlr_xdg_surface.c:325
EE 28-10-20 11:56:08.418 - #7  destroy_resource /home/dkondor/program/wayland/src/wayland-server.c:726
EE 28-10-20 11:56:08.429 - #8  wl_resource_destroy /home/dkondor/program/wayland/src/wayland-server.c:743
EE 28-10-20 11:56:08.441 - #9  xdg_surface_handle_destroy ../types/xdg_shell/wlr_xdg_surface.c:309
EE 28-10-20 11:56:08.449 - #10 ffi_call_unix64 ??:?
EE 28-10-20 11:56:08.459 - #11 ffi_call ??:?
EE 28-10-20 11:56:08.467 - #12 wl_closure_invoke /home/dkondor/program/wayland/src/connection.c:1020
EE 28-10-20 11:56:08.476 - #13 wl_client_connection_data /home/dkondor/program/wayland/src/wayland-server.c:432
EE 28-10-20 11:56:08.486 - #14 wl_event_loop_dispatch /home/dkondor/program/wayland/src/event-loop.c:1027
EE 28-10-20 11:56:08.496 - #15 wl_display_run /home/dkondor/program/wayland/src/wayland-server.c:1349
EE 28-10-20 11:56:08.527 - #16 main ../src/main.cpp:394
EE 28-10-20 11:56:08.662 - #17 __libc_start_main ../csu/libc-start.c:344
EE 28-10-20 11:56:08.703 - #18 ?? ??:0

@ammen99
Copy link
Member Author

ammen99 commented Oct 28, 2020

@dkondor I think I saw the problem, reset_xdg_surface might be called multiple times for the same toplevel/popup. I have fixed this issue, please try again.

@dkondor
Copy link
Contributor

dkondor commented Oct 28, 2020

Yes, it's working now; also, my original issue with cairo-dock is resolved as well. Thanks!

@travankor
Copy link

Should it send a protocol error, too? See: #2057

@ammen99
Copy link
Member Author

ammen99 commented Oct 28, 2020

Should it send a protocol error, too? See: #2057

No, it shouldn't. This is simply a race condition which neither wlroots nor the client can prevent, and necessitates an inert state of objects on the wlroots side.

@travankor does this also fix your issue with chromium on Wayland?

@emersion emersion self-requested a review October 28, 2020 10:05
@travankor
Copy link

travankor commented Oct 28, 2020

does this also fix your issue with chromium on Wayland?

I can't test that anymore since the bug only worked on v80 and previous releases. And I cleaned my package cache in September, unfortunately, because of disk space running out.

@emersion emersion added this to the 0.12.0 milestone Nov 4, 2020
@ammen99
Copy link
Member Author

ammen99 commented Nov 6, 2020

I did not know that you can destroy and re-create the xdg_toplevel without doing the same for xdg_surface. Unfortunately, this means we just need to remove one of the errors for clients, let me know if you find this acceptable.

@emersion
Copy link
Member

emersion commented Nov 7, 2020

Can we add an explanation of why this is necessary to the commit message? Otherwise I won't remember. Something among those lines:

xdg_popups can be destroyed by the compositor when closed. When this happens,
wlroots makes the xdg_popup surface inert and resets the xdg_surface role to
NONE.

Currently, wlroots sends a protocol error and asserts that an xdg_surface has
a role when committed. This is racy if at the same time the client commits an
xdg_popup and the compositor closes it. This patch removes the assertion and
ignores commits on xdg_surfaces without a role set.

@ammen99
Copy link
Member Author

ammen99 commented Nov 8, 2020

I updated the patch as you suggested. Thanks for the in-depth review, I know so little about the xdg-shell implementation.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Thanks for the in-depth review, I know so little about the xdg-shell implementation.

No problem, the xdg-shell implementation isn't the most straightforward part of wlroots sadly.

types/xdg_shell/wlr_xdg_surface.c Outdated Show resolved Hide resolved
xdg_popups can be destroyed by the compositor when closed. When this happens,
wlroots makes the xdg_popup surface inert and resets the xdg_surface role to
NONE.

Currently, wlroots sends a protocol error and asserts that an xdg_surface has
a role when committed. This is racy if at the same time the client commits an
xdg_popup and the compositor closes it. This patch removes the assertion and
ignores commits on xdg_surfaces without a role set.
@ammen99 ammen99 requested a review from emersion November 8, 2020 11:35
Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Forgot to push?

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

race condition when closing popups
4 participants