BuddiesOfBudgie / budgie-desktop

Budgie Desktop is a familiar, modern desktop environment.
https://buddiesofbudgie.org
GNU General Public License v2.0
957 stars 50 forks source link

[Bug] Unresponsive panel when Discord is open #456

Closed elusian closed 1 year ago

elusian commented 1 year ago

Description

Since Budgie 10.8, Discord is having issues with the tray. Periodically, the icon shown in the tray switches to a generic one, and whenever that happens all panels and applets are unresponsive.

Snapshot_2023-09-17_15-58-39

The green icon on the left here is supposed to be Discord.

Whenever it happens, the system log also receives logs such as

Received property WindowId with type i does not match expected type u in the expected interface

and the CPU usage of budgie-panel rises to a full core.

Budgie version

10.8

Operating System

Solus 4 updated to 16/09/2023

Steps to reproduce the issue

1: Have the system tray applet in a panel 2: open Discord (flatpak version in my case) 3: wait for the icon to change (random chance), use another applet (e.g. try to switch window form the icon task list)

Actual result

Bugged Discord icon, all panel interactions while icon is wrong are ignored, high CPU usage from budgie-panel

Expected result

Discord keeps the correct icon, panels stay responsive and has normal CPU usage

Additional information

No response

JoshStrobl commented 1 year ago

This is an issue with all Electron-based applications and not an actionable item on our party.

elusian commented 1 year ago

I suspected as much for the icon, but I hoped for a solution for the unresponsive panel

JoshStrobl commented 1 year ago

Will re-open pending additional logs. If you could follow https://docs.buddiesofbudgie.org/developer/workflow/providing-backtraces it would be very helpful.

elusian commented 1 year ago

I tried following the instructions for a while, but the problem is that it does not segfault, so I don't have a chance to request a backtrace in gdb. I can try more later, otherwise let me know if you have other ideas

elusian commented 1 year ago

Just wanted to say that I did not forget about this, I'm just very busy this week. I will upload some logs as soon as possible.

elusian commented 1 year ago

So, as mentioned before gdb is not helpful, since nothing is crashing.

What I can provide is a flamegraph with

flame4

and without Discord open

flameGood

(These are interactive SVG, but just opening from GitHub does not seem to make them work. I had to download them and then reopen them in browser)

During the record in the first link, the panel was continuously unresponsive (for >5 min, I had to replace the panel, otherwise I could not close Discord).

I hope this helps, let me know if I can provide other information.

serebit commented 1 year ago

theme_subdir_load should not be running for that long...

elusian commented 1 year ago

I see this is still marked as "Needs more info", is it a leftover or do you actually need more info from me?

serebit commented 1 year ago

Found the function in GTK. It does what I assumed it does, which is traverse the icon theme paths that it's given. There are a few places in that function where it could be halting - several internal loops. Do the following:

Once the panel freezes, enter Ctrl-C into GDB so it halts the program, then enter backtrace and copy the results here. That should give us some idea where in that function GTK is spinning its wheels.

elusian commented 1 year ago

Ok, fair, I should have thought about Ctrl+C. I will have the results as soon as possible

elusian commented 1 year ago

Here's the backtrace

#0  0x00007ffff7583f82 in theme_subdir_load
    (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme], theme=theme@entry=0x55555a3b6690, theme_file=theme_file@entry=0x555559ef1d10, subdir=0x55555a36e480 "84x84/apps")
    at ../gtk/gtkicontheme.c:3370
#1  0x00007ffff75846a1 in insert_theme (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme], theme_name=<optimized out>) at ../gtk/gtkicontheme.c:1239
#2  0x00007ffff7584726 in insert_theme (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme], theme_name=<optimized out>) at ../gtk/gtkicontheme.c:1259
#3  0x00007ffff7584726 in insert_theme (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme], theme_name=<optimized out>) at ../gtk/gtkicontheme.c:1259
#4  0x00007ffff7584c07 in load_themes (icon_theme=0x55555564ae90 [GtkIconTheme]) at ../gtk/gtkicontheme.c:1373
#5  ensure_valid_themes (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme]) at ../gtk/gtkicontheme.c:1482
#6  0x00007ffff758577a in gtk_icon_theme_has_icon (icon_theme=icon_theme@entry=0x55555564ae90 [GtkIconTheme], icon_name=icon_name@entry=0x55555a37baf0 "status_icon_771") at ../gtk/gtkicontheme.c:2458
#7  0x00007fffc5ba7300 in tray_item_update_icon
    (fallback_icon_name=<optimized out>, icon_pixmaps_length1=<optimized out>, icon_pixmaps=<optimized out>, icon_name=<optimized out>, icon=<optimized out>, self=<optimized out>)
    at src/panel/applets/tray/libtrayapplet.so.p/TrayItem.c:3062
#8  tray_item_update_icon
    (self=0x5555592ecd00 [TrayItem], icon=0x5555592f0490 [GtkImage], icon_name=0x55555a37baf0 "status_icon_771", icon_pixmaps=<optimized out>, icon_pixmaps_length1=<optimized out>, fallback_icon_name=<optimized out>) at src/panel/applets/tray/libtrayapplet.so.p/TrayItem.c:2987
#9  0x00007fffc5ba8429 in tray_item_reset_icon (self=0x5555592ecd00 [TrayItem], status=0x0) at src/panel/applets/tray/libtrayapplet.so.p/TrayItem.c:2918
#13 0x00007ffff7d092dc in <emit signal 0x7fffc5bac854 "new-icon" or new-icon on instance 0x5555592ece90 [SnItemInterfaceProxy]>
    (instance=instance@entry=0x5555592ece90, detailed_signal=detailed_signal@entry=0x7fffc5bac854 "new-icon") at ../gobject/gsignal.c:3664
    #10 0x00007ffff7ceef70 in g_closure_invoke
    (closure=0x555555a356c0, return_value=return_value@entry=0x0, n_param_values=1, param_values=param_values@entry=0x7fffffffd9f0, invocation_hint=invocation_hint@entry=0x7fffffffd970)
    at ../gobject/gclosure.c:832
    #11 0x00007ffff7d02218 in signal_emit_unlocked_R
    (node=node@entry=0x55555864b1a0, detail=detail@entry=0, instance=instance@entry=0x5555592ece90, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffd9f0)
    at ../gobject/gsignal.c:3812
    #12 0x00007ffff7d08eea in g_signal_emit_valist (instance=instance@entry=0x5555592ece90, signal_id=signal_id@entry=709, detail=<optimized out>, var_args=var_args@entry=0x7fffffffdb88)
    at ../gobject/gsignal.c:3565
#14 0x00007fffc5ba64ca in _dbus_handle_sn_item_interface_new_icon (parameters=0x55555a0a5e10, self=0x5555592ece90) at src/panel/applets/tray/libtrayapplet.so.p/TrayItem.c:1933
#15 sn_item_interface_proxy_g_signal (proxy=0x5555592ece90 [SnItemInterfaceProxy], sender_name=<optimized out>, signal_name=0x7fffdc360070 "NewIcon", parameters=0x55555a0a5e10)
    at src/panel/applets/tray/libtrayapplet.so.p/TrayItem.c:2002
#19 0x00007ffff7d090c0 in <emit signal g-signal on instance 0x5555592ece90 [SnItemInterfaceProxy]> (instance=instance@entry=0x5555592ece90, signal_id=<optimized out>, detail=<optimized out>)
    at ../gobject/gsignal.c:3622
    #16 0x00007ffff7ceef70 in g_closure_invoke
    (closure=closure@entry=0x555555604440, return_value=return_value@entry=0x0, n_param_values=4, param_values=param_values@entry=0x7fffffffdf10, invocation_hint=invocation_hint@entry=0x7fffffffde90)
    at ../gobject/gclosure.c:832
    #17 0x00007ffff7d02347 in signal_emit_unlocked_R
    (node=node@entry=0x5555555d4f90, detail=detail@entry=0, instance=instance@entry=0x5555592ece90, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffdf10)
    at ../gobject/gsignal.c:3851
    #18 0x00007ffff7d08eea in g_signal_emit_valist (instance=<optimized out>, signal_id=<optimized out>, detail=<optimized out>, var_args=var_args@entry=0x7fffffffe0e0) at ../gobject/gsignal.c:3565
#20 0x00007ffff7e56abf in on_signal_received
    (connection=<optimized out>, sender_name=0x7fffdc061f30 ":1.386", object_path=<optimized out>, interface_name=<optimized out>, signal_name=0x7fffdc05f490 "NewIcon", parameters=0x55555a0a5e10, user_data=0x5555592edda0) at ../gio/gdbusproxy.c:890
#21 0x00007ffff7e43f24 in emit_signal_instance_in_idle_cb (data=0x7fffdc343720) at ../gio/gdbusconnection.c:3802
#22 0x00007ffff7bed1c0 in g_main_dispatch (context=0x5555555e5bb0) at ../glib/gmain.c:3460
#23 g_main_context_dispatch (context=context@entry=0x5555555e5bb0) at ../glib/gmain.c:4200
#24 0x00007ffff7bed5b9 in g_main_context_iterate (context=0x5555555e5bb0, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4276
#25 0x00007ffff7bed87f in g_main_loop_run (loop=loop@entry=0x55555572c580) at ../glib/gmain.c:4479
#26 0x00007ffff75b37c7 in gtk_main () at ../gtk/gtkmain.c:1329
#27 0x0000555555566202 in _vala_main (args_length1=<optimized out>, args=<optimized out>) at src/panel/budgie-panel.p/main.c:133
#28 main (argc=<optimized out>, argv=<optimized out>) at src/panel/budgie-panel.p/main.c:144

I tried a few times, and I noticed that the number of calls to insert_theme at ../gtk/gtkicontheme.c:1259 varies between 3 and 4

serebit commented 1 year ago

Is it consistently locking at ../gtk/gtkicontheme.c:3370?

elusian commented 1 year ago

In the few tries I did, yes

serebit commented 1 year ago

That's... odd. It seems like GTK is getting stuck in this loop:

for (d = icon_theme->priv->dir_mtimes; d; d = d->next)
    {
      dir_mtime = (IconThemeDirMtime *)d->data;

      if (!dir_mtime->exists) // locking here
        continue; /* directory doesn't exist */

      // ...
    }

If it truly is stuck in an infinite loop, then the only reason this could happen is that the linked list being iterated over is circular, but that almost seems too simple...

elusian commented 1 year ago

It cannot be infinite, it does exit, it's just arbitrarily slow to do so. It can get stuck for a few instants, for a few minutes or even for more than I cared to wait (>20min, then I replaced the panel).

serebit commented 1 year ago

Hm... Let's see if this helps. Clone this repo, and build it according to the Solus instructions on the docs site.

Then, change this line: https://github.com/BuddiesOfBudgie/budgie-desktop/blob/7dfa0268bb87bf53a4b2319f695df4244858f5b7/src/panel/applets/tray/TrayItem.vala#L166

To var icon_theme = new Gtk.IconTheme();.

Then install and log out and back in.

elusian commented 1 year ago

Ok, I can try, but likely on Thursday, I cannot risk breaking stuff before tomorrow.

elusian commented 1 year ago

So, on one hand the panel looks responsive, on the other hand now the icon for Discord (and Skype too, so I suspect it may be all Electron applications) is always the generic one.

This also means that unless I'm constantly interacting with the panel I may not notice the issue if it disappears fast enough...

serebit commented 1 year ago

Try the branch 456-bug-unresponsive-panel-when-discord-is-open. I believe I've fixed the oversight in the algorithm that caused this, but I haven't been able to reproduce the problem myself, so I'll need you to test.

elusian commented 1 year ago

I tried a few times these evenings, it seems to work. I did not notice issues with the panel, and even the icon stays correct.

serebit commented 1 year ago

Excellent. I'll open a MR with the change.

elusian commented 1 year ago

Thank you!