Bug 389132 - plasmashell's notification history seems to have no upper limit
Summary: plasmashell's notification history seems to have no upper limit
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Notifications (show other bugs)
Version: 5.11.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 1.0
Assignee: Kai Uwe Broulik
URL:
Keywords:
: 387128 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-01-17 22:03 UTC by Nicolas F.
Modified: 2018-03-12 16:42 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.12.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas F. 2018-01-17 22:03:38 UTC
It appears that plasmashell's notification history does not have an upper limit, which means that buggy applications may accidentally OOM the system through plasmashell by creating a lot of notifications.

In my case, qBittorrent spams a notification for every IOError it encounters (happens quite often when you accidentally disconnect the external drive), which quickly leads to plasmashell's memory usage ballooning in size to several gigabytes.

plasmashell could enforce a per-PID maximum number of notifications that it keeps in its history to prevent this from happening, discarding old notifications as new ones come in if the limit is reached.
Comment 1 Nate Graham 2018-01-18 15:16:42 UTC
In addition, please file a bug report on QBittorrent; spamming the shell with notifications on every error isn't good practice.
Comment 2 David Edmundson 2018-01-18 15:27:10 UTC
I don't think we need a fancy limit, we just need to change the code to not keep UI delegates around. This is something that's already on the TODO list as it's a big memory hog.
Comment 3 Nicolas F. 2018-01-18 22:28:38 UTC
>In addition, please file a bug report on QBittorrent; spamming the shell with notifications on every error isn't good practice.

I've already done this a while ago[1], turns out plasmashell isn't the only environment that has issues with notification spam (Windows doesn't seem to like it either).

Thanks for the quick response.

[1] https://github.com/qbittorrent/qBittorrent/issues/7586
Comment 4 Kai Uwe Broulik 2018-01-19 09:09:47 UTC
I made a, rather ugly, patch: https://phabricator.kde.org/D9979 If you could give it a try?
Comment 5 Kai Uwe Broulik 2018-01-19 09:10:01 UTC
Wrong link: https://phabricator.kde.org/D9978 that's the correct one
Comment 6 Kai Uwe Broulik 2018-01-19 09:56:57 UTC
Git commit e8f76cc5386d7bc2878f4b72dc6e177164b3ad85 by Kai Uwe Broulik.
Committed on 19/01/2018 at 09:55.
Pushed by broulik into branch 'master'.

[Notifications] Put history into a ListView

Notification uses Repeaters for everything. While this is acceptable for jobs and notifications, of which there are few,
the history can turn into a very long list of items. Using a ListView solves memory consumption by creating delegates only as needed.
Since regular notifications and notification history are quite entangled with each other, I had to configure the ListView
from within the Notifications loader. To keep code changes as little as possible, the rest of the UI is just moved into
the ListView header item.

While this is quite an invasive patch for a feature frozen version it's the least invasive approach I could find and is quite
an important memory leak fix for an LTS.
FIXED-IN: 5.12.0

CHANGELOG: Fixed memory leak when there are a lot of items in notification history

Differential Revision: https://phabricator.kde.org/D9978

M  +1    -1    applets/notifications/package/contents/ui/NotificationDelegate.qml
M  +24   -7    applets/notifications/package/contents/ui/Notifications.qml
M  +17   -40   applets/notifications/package/contents/ui/main.qml

https://commits.kde.org/plasma-workspace/e8f76cc5386d7bc2878f4b72dc6e177164b3ad85
Comment 7 Kai Uwe Broulik 2018-01-19 13:45:21 UTC
Git commit 59d66e30a6483096dd05525000f2e34713dfba5c by Kai Uwe Broulik.
Committed on 19/01/2018 at 13:43.
Pushed by broulik into branch 'Plasma/5.12'.

[Notifications] Put history into a ListView

Notification uses Repeaters for everything. While this is acceptable for jobs and notifications, of which there are few,
the history can turn into a very long list of items. Using a ListView solves memory consumption by creating delegates only as needed.
Since regular notifications and notification history are quite entangled with each other, I had to configure the ListView
from within the Notifications loader. To keep code changes as little as possible, the rest of the UI is just moved into
the ListView header item.

While this is quite an invasive patch for a feature frozen version it's the least invasive approach I could find and is quite
an important memory leak fix for an LTS.
FIXED-IN: 5.12.0

CHANGELOG: Fixed memory leak when there are a lot of items in notification history

Differential Revision: https://phabricator.kde.org/D9978

(cherry picked from commit e8f76cc5386d7bc2878f4b72dc6e177164b3ad85)

M  +1    -1    applets/notifications/package/contents/ui/NotificationDelegate.qml
M  +24   -7    applets/notifications/package/contents/ui/Notifications.qml
M  +17   -40   applets/notifications/package/contents/ui/main.qml

https://commits.kde.org/plasma-workspace/59d66e30a6483096dd05525000f2e34713dfba5c
Comment 8 Nicolas F. 2018-01-19 17:56:21 UTC
I've applied the patch to plasmashell 5.11.5, and tested it.

The good news is that it drastically reduced the memory usage from the notification spam. Even after minutes of waiting, plasmashell only climbed up to about 400 MiB used memory. I could even open the notifications area this time, which previously would immediately OOM the system.

The bad news is that when dismissing the notifications (which I previously couldn't do, because the system was very busy), the memory usage actually increases by about 300K per dismissed notification. It doesn't seem to decrease again after waiting a while either. (The lack of a "dismiss all" button for the notification applet also means that a user has to do a solid 10 minutes of clicking to get their notifications back in order)

Seems good enough for now though, the memory leak is much much smaller now.
Comment 9 Kai Uwe Broulik 2018-01-22 09:09:23 UTC
> The lack of a "dismiss all" button for the notification applet also means that a user has to do a solid 10 minutes of clicking to get their notifications back in order

You can use the "Clear notifications" in notification applet context menu. I'll        see if I can add a visible clear button next to the history header.
Comment 10 Kai Uwe Broulik 2018-03-12 12:22:11 UTC
*** Bug 387128 has been marked as a duplicate of this bug. ***
Comment 11 Nate Graham 2018-03-12 16:42:20 UTC
A "Clear Notifications" buttons just went in today, FWIW: Bug 386068