Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Don't ask, don't tell" focus hack causes gnome-shell to freeze for seconds / Xwayland to crash #714

Closed
jwrdegoede opened this issue Feb 16, 2023 · 8 comments · Fixed by #716

Comments

@jwrdegoede
Copy link

jwrdegoede commented Feb 16, 2023

Lately I have been having these weird issues where gnome-shell freezes for second and often Xwayland crashes. I have been working with the mutter + Xwayland devs to get to the bottom of this.

Let me copy and paste the summary which I added to a related (workaround) mutter pull-request for this:

I have been seeing mutter freezing for seconds / Xwayland crashes / mutter crashes when starting terminator for a while now.

After collecting backtraces I emailed @carlosg and @ofourdan to see if we could make sense of this.

The Xwayland logs showed a crash due to running out of libwayland buffer space and the crashes actually go away with: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/188 which makes libwayland dynamically grow the buffer.

The mutter backtrace showed mutter crashing inside meta-x11-display: update_cursor_theme(), it seems that if Xwayland crashes at the wrong moment it manages to take mutter down with it. These too appear to be resolved by the libwayland change to dynamically grow the buffer.

If Xwayland no longer crashes then things just freeze for a couple of seconds when starting terminator and after that everything works normally again.

Commenting out the g_signal_connect_object("cursor-updated", update_cursor_theme) call can be used as a workaround for the freezes.

@ofourdan has managed to reproduce this by using my ~/.config/terminator/config file. I will attach that here. For me this reproduces by just starting terminator with this config in a gnome-shell which has already had at least one other app opened. I'm on a fully up2date Fedora 37 install.

Further debugging has turned out that this is caused by repeated gdk_window_focus() API calls. Which lead me to:

# Awful workaround to be sure that the last focused window is actually the one focused.
and commenting that out indeed fixes the freezes caused by starting terminator.

It looks like to me like this workaround is causing more harm then whatever focus issue it is trying to fix., so maybe remove it?

You can reach out to the gnome-shell devs in: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2849 Where a workaround for this terminator mis-behavior is being discussed. I'm sure they would be happy to discuss a better way to deal with whatever focus issue this is trying to fix (or at least fix it under gnome-shell).

@jwrdegoede jwrdegoede changed the title Don't ask, don't tellTerminator causes gnome-shell to freeze for seconds / Xwayland to crash, caused by " "Don't ask, don't tell" focus hack causes gnome-shell to freeze for seconds / Xwayland to crash Feb 16, 2023
@jwrdegoede
Copy link
Author

I accidentally hit submit before actually writing my bug report. I have just edited the original description to actually be a proper bug report, so if you are following this via email, please check the new description on github.com.

Here is my terminator config.txt, which is necessary to reproduce this problem.

@krnhotwings
Copy link

krnhotwings commented Feb 18, 2023

I've had a similar (or exact same) issue where using terminator in wayland will 'cause gnome shell to freeze up for a few seconds, and the mouse cursor will rapidly blink the wait spinner while something is preventing terminator from launching. Opening a separate application window (e.g. nautilus) and focusing that window will cause terminator to draw the window. This isn't exhibited in "gnome on xorg" mode.

I've found that removing the last_active_term and last_active_window settings stops the above behavior on wayland. I'm not sure which of the two causes the behavior; haven't bothered to figure it out as I was just relieved that the problem went away...

@jwrdegoede
Copy link
Author

The problematic code block starts with 'if self.last_active_window:' so yes disabling the last_active_window option should workaround this.

Maybe that option should simply be removed all together? Or at least default to off ?

@mattrose
Copy link
Member

mattrose commented Mar 1, 2023

Maybe that option should simply be removed all together? Or at least default to off ?

Oh it very much defaults to off, but you do have it set in your config, so that's why you're running into this problem. I made #716 that should non-heroically fix the problem. It just sets the focus to be the last_active_window specified in the config, and leaves it at that. Can you try it out and make sure that it works as you expect?

@mattrose
Copy link
Member

mattrose commented Mar 1, 2023

The original commit actually explains in a comment why Steve Boddy did such a thing. It makes for interesting reading.

@krnhotwings
Copy link

I've tried the branch out, and it seems to be working fine on my end, though I can't say with absolute certainty. My testing process went as follows:

  1. Running on Silverblue, so made a separate toolbox/container, installed the python deps listed in INSTALL.md
  2. Cloned both gnome-terminator/terminator and your fork
  3. Launched gnome-terminal, cd'd to gnome-terminator/terminator
  4. Ran sleep 3 && python3 terminator. The sleep gave me time to click away from gnome-terminal (in my case, the desktop,) which would allow terminator to trigger the launch issue described in this issue. Observed that the freezing issue occurred.
  5. Ran the same process against the fork's branch and observed that the freezing issue did not occur.

Looks good on my end. Thank you, @mattrose!

@jwrdegoede
Copy link
Author

Oh it very much defaults to off, but you do have it set in your config, so that's why you're running into this problem.

Ah, I don't remember turning that on and I cannot find it anywhere in the settings UI. But maybe I'm just not looking in the right place.

I made #716 that should non-heroically fix the problem.

Thanks, that looks good to me (I didn't find the time to test, sorry).

gnomesysadmins pushed a commit to GNOME/mutter that referenced this issue Mar 4, 2023
This is what "terminator" (the terminal emulator) does, it basically
calls gdk_window_focus() in a loop thousands of times at startup.

This in turn fills up the Wayland connection between Xwayland and
mutter, and eventually the session dies.

See-also: gnome-terminator/terminator#714
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2849>
@mattrose
Copy link
Member

mattrose commented Mar 9, 2023

@jwrdegoede those config parameters get turned on when you save a layout. They tell terminator which window and terminal to focus on when the layout is completely done. I'm gonna merge this in now. Thanks @krnhotwings for testing it out.

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 a pull request may close this issue.

3 participants