! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
Running multiple mousepad instances shows a huge dbus trafic with dconf-relat...
Status:
RESOLVED: FIXED
Product:
Mousepad
Component:
General

Comments

Description Yves-Alexis Perez editbugs 2015-08-12 23:22:33 CEST
Hi,

a Debian user reported (and I can confirm it) that running multiple mousepad instances currently leads to a lot of dbus traffic (shown in dbus-monitor), which is apparently about dconf settings. That also use a lot of CPU, so setting the severity to major.

The downstream bug is at http://bugs.debian.org/795192
Comment 1 Matthew Brush editbugs 2015-08-13 01:06:38 CEST
Weird. It should only be sending GSettings stuff when the settings are accessed. The linked bug shows it's the color-scheme setting, which is even more puzzling as it should only be accessed very rarely compared to some stuff like keeping track of the windows' positions as they move around and whatnot.

I'll try and see if I can reproduce here. In the meantime, a "workaround" is to not use the Dbus backend of GSettings (using `--enable-keyfile-settings` option to `configure` script).

There's existing non-GSettings code that uses Dbus in Mousepad too, which I think can also be disabled (probably `--disable-dbus` option to `configure` script), that I believe is used for single-instance multi-window support. Hopefully it's not related to that code, as I've never looked at it and have no idea how it works.
Comment 2 OmegaPhil 2015-08-31 21:26:24 CEST
Sorry I didn't get any email on the Debian bug so I didn't realise anything had happened (control messages aren't sent to subscribers).

I can confirm '--enable-keyfile-settings' alone to configure is enough to kill off this problem.
Comment 3 Titon 2015-09-27 16:40:37 CEST
Hi,
I can confirm that this bug exists ( in debian testing ).

Running a 'dconf watch /' command in a separate terminal shows that mousepad is trying to change a color scheme related settings, apparently hundreds of times each second. 

$ dconf watch /
"""
/org/xfce/mousepad/preferences/view/color-scheme
   '[Invalid UTF-8]'


/org/xfce/mousepad/preferences/view/color-scheme
   '[Invalid UTF-8]'

"""


System starts showing high amount of disk writes caused by 'dconf-service' and 'jbd2/ext4', eventually stalling everything. I am worried about SSD write cycle wastage due to this bug. :(  


$ mousepad -v
"""
Mousepad 0.4.0

Copyright (c) 2007
	The Xfce development team. All rights reserved.

Please report bugs to <http://bugzilla.xfce.org/>.
"""


$ dpkg -l mousepad
"""
||/ Name           Version      Architecture Description
+++-==============-============-============-==================================
ii  mousepad       0.4.0-3      amd64        simple Xfce oriented text editor
"""
Comment 4 Matthew Brush editbugs 2015-09-27 20:57:22 CEST
I can repeat it too, though here the CPU load is only around 1% when the bug occurs. There must be some cycle or something, maybe weird interaction between the low-level DBus single-instance code and the new GSettings stuff added later. The bug doesn't occur when you open a new window using File->New Window.
Comment 5 Matthew Brush editbugs 2015-09-27 22:24:09 CEST
I added a fix for this:

http://git.xfce.org/apps/mousepad/commit/?id=f07cc75f2aa77d14f16b5506321ac6a2413706ba

As mentioned in the commit message, I'm not entirely sure what's going on, but it seems to fix the problem here.

Can anyone confirm?
Comment 6 Yves-Alexis Perez editbugs 2015-09-27 23:08:14 CEST
(In reply to Matthew Brush from comment #5)
> I added a fix for this:
> 
> http://git.xfce.org/apps/mousepad/commit/
> ?id=f07cc75f2aa77d14f16b5506321ac6a2413706ba
> 
> As mentioned in the commit message, I'm not entirely sure what's going on,
> but it seems to fix the problem here.
> 
> Can anyone confirm?

It doesn't seem to work here.
Comment 7 Matthew Brush editbugs 2015-09-27 23:33:32 CEST
(In reply to Yves-Alexis Perez from comment #6)
> (In reply to Matthew Brush from comment #5)
> > I added a fix for this:
> > 
> > http://git.xfce.org/apps/mousepad/commit/
> > ?id=f07cc75f2aa77d14f16b5506321ac6a2413706ba
> > 
> > As mentioned in the commit message, I'm not entirely sure what's going on,
> > but it seems to fix the problem here.
> > 
> > Can anyone confirm?
> 
> It doesn't seem to work here.

You definitively don't have any existing Mousepad instances open before testing? I have installed into `/opt/mousepad` prefix, and tested by running `/opt/mousepad/bin/mousepad` twice and watching output of `dconf watch /`. It just does the expected DBus activities for me, in this case, to keep settings in sync. Before this change it just spammed an infinite number of messages about the 'color-scheme'.
Comment 8 Yves-Alexis Perez editbugs 2015-09-28 22:15:43 CEST
(In reply to Matthew Brush from comment #7)
> (In reply to Yves-Alexis Perez from comment #6)
> > It doesn't seem to work here.
> 
> You definitively don't have any existing Mousepad instances open before
> testing? I have installed into `/opt/mousepad` prefix, and tested by running
> `/opt/mousepad/bin/mousepad` twice and watching output of `dconf watch /`.
> It just does the expected DBus activities for me, in this case, to keep
> settings in sync. Before this change it just spammed an infinite number of
> messages about the 'color-scheme'.

I still have the infinite number of message, and yes it's a clear start. Mousepad is built with:

* D-BUS support:             no
* Debug Support:             minimum
* Use keyfile backend:       default
* Build with GTK+ 3:         no
Comment 9 Matthew Brush editbugs 2015-09-29 16:25:18 CEST
(In reply to Yves-Alexis Perez from comment #8)
> (In reply to Matthew Brush from comment #7)
> > (In reply to Yves-Alexis Perez from comment #6)
> > > It doesn't seem to work here.
> > 
> > You definitively don't have any existing Mousepad instances open before
> > testing? I have installed into `/opt/mousepad` prefix, and tested by running
> > `/opt/mousepad/bin/mousepad` twice and watching output of `dconf watch /`.
> > It just does the expected DBus activities for me, in this case, to keep
> > settings in sync. Before this change it just spammed an infinite number of
> > messages about the 'color-scheme'.
> 
> I still have the infinite number of message, and yes it's a clear start.
> Mousepad is built with:
> 
> * D-BUS support:             no
> * Debug Support:             minimum
> * Use keyfile backend:       default
> * Build with GTK+ 3:         no

Not sure if it matters but the only difference here is using DBUS-support enabled (for proper multi-instance support) and GTK+3 enabled.
Comment 10 Yves-Alexis Perez editbugs 2015-09-29 21:15:38 CEST
I'll try to rebuild with DBus support forced and report back.
Comment 11 Alistair Buxton 2016-03-22 00:08:32 CET
The true cause of this problem is inside mousepad-action-group.c. This is the code for the color theme menu. In it there are two functions:


1. mousepad_action_group_style_scheme_action_activate

This is called when the user uses the menu to change the theme. It's job is to change the g_setting.

2. mousepad_action_group_color_scheme_setting_changed

This is called whenever the g_setting changed. It's job is to change the currently selected item in the menu.

The problem is that both these functions do more than just their job. They both call:

3. mousepad_action_group_set_active_style_scheme

This function activates a lock so it will only be called once. Then it updates both the menu and the g_setting. The lock prevents the resulting triggered events from running.

The problem comes when you have more than one window open. The lock means that each window will only try to update the menu and the setting once. But updating the setting will trigger every other unlocked window to update the menu and the setting. So then the next unlocked window locks itself and then triggers another event in all the remaining windows. This causes a huge cascade of events which will all (eventually) get ignored by the lock.

The solution is to change the logic so that updating the setting only triggers a menu update, and updating the menu only triggers a setting update. Each will in turn trigger an attempt at updating the other, but now the lock will prevent it from happening, and therefore prevent a setting change from being propagated back out to other windows.
Comment 12 Alistair Buxton 2016-03-22 00:15:37 CET
This isn't the full extent of the problem though. Whenever the setting or the menu changed, the action group also sends an event to the window, which passes it to the view. But the view is also bound directly to the setting. So when the setting changes this happens:

1. View gets a notification and updates.
2. Menu gets a notification and and manually tells the view to update.
3. Menu unnecessarily updates the g_setting.
4. View gets another notification and updates for a third time.

So for every spam caused by the loop described in the previous comment, the view_set_color_theme function gets called three times, which means even more queued events. It's possible for mousepad to get OOM killed because the event queue just grows exponentially with the number of open windows.
Comment 13 Alistair Buxton 2016-03-22 00:40:21 CET
Created attachment 6632 
Revert original patch
Comment 14 Alistair Buxton 2016-03-22 00:42:01 CET
Created attachment 6633 
Prevent the menu item/g_setting cycle.
Comment 15 Alistair Buxton 2016-03-22 00:44:58 CET
Created attachment 6634 
Don't manually update the view.

This just removes mousepad_window_action_group_style_scheme_changed completely as it doesn't seem to do anything useful.
Comment 16 Alistair Buxton 2016-03-22 00:52:30 CET
Created attachment 6635 
Prevent the menu item/g_setting cycle - fixed

Some unintentional changes got through in the old version of this patch.
Comment 17 Yves-Alexis Perez editbugs 2016-06-12 18:27:04 CEST
I'm a bit lost here, can one mark obsolete the insufficient patches and check the right one(s) (even better would be to commit it to git but I understand it might not be that easy.
Comment 18 Alistair Buxton 2016-06-12 19:11:58 CEST
(In reply to Yves-Alexis Perez from comment #17)
> I'm a bit lost here, can one mark obsolete the insufficient patches and
> check the right one(s) (even better would be to commit it to git but I
> understand it might not be that easy.

I've already done this. You need all three remaining patches.

I tried to push this to my user repository, but it didn't work. So I pushed it to github instead, and then created a pull request (against my own repository in order to prevent noise on the semi-official mirror):

https://github.com/ali1234/mousepad/pull/1
Comment 19 Alistair Buxton 2016-06-27 20:32:26 CEST
*** Bug 11927 has been marked as a duplicate of this bug. ***
Comment 20 ToZ editbugs 2016-10-18 02:37:43 CEST
Applying the patch from Alistair's comment #18 fixes the issue for me on Arch. 

Patch file: https://patch-diff.githubusercontent.com/raw/ali1234/mousepad/pull/1.patch
Comment 21 Johnny Lee 2016-11-24 22:25:52 CET
I confirm that this bug still continues/exists on xubuntu 16.04 with dconf-service. It happens on my machine when I open more than one instance of mousepad, the I/O disk write increments and the HDD led doesn't stop blinking, until I close one of the instances of mousepad.
Comment 22 Alistair Buxton 2017-08-06 17:49:41 CEST
Can this be pulled please?
Comment 23 Matthew Brush editbugs 2017-08-15 04:12:25 CEST
This is finally merged, sorry for the extremely long delay. Thanks for the fix!

https://git.xfce.org/apps/mousepad/commit/?id=309f6177d2c47070676d6c733e29952c63c110ba
Comment 24 Matthew Brush editbugs 2017-08-15 04:13:45 CEST
...won't let me change to resolved-fixed without comment...

Bug #12134

Reported by:
Yves-Alexis Perez
Reported on: 2015-08-12
Last modified on: 2017-08-15
Duplicates (1):
  • 11927 Mousepad gets stuck in a busyloop

People

Assignee:
Matthew Brush
CC List:
7 users

Version

Target Milestone:
Mousepad 0.2.x

Attachments

Revert original patch (1.45 KB, patch)
2016-03-22 00:40 CET , Alistair Buxton
no flags
Prevent the menu item/g_setting cycle. (2.88 KB, patch)
2016-03-22 00:42 CET , Alistair Buxton
no flags
Don't manually update the view. (2.36 KB, patch)
2016-03-22 00:44 CET , Alistair Buxton
no flags
Prevent the menu item/g_setting cycle - fixed (2.51 KB, patch)
2016-03-22 00:52 CET , Alistair Buxton
no flags

Additional information