Notifications crash and plasma apps freeze after some uptime

I also suspected that xdg-desktop-portal-kde could be culprit. But after monitoring the D-Bus user session, I saw that the Flatpak app used org.freedesktop.Notifications directly.

I can reliably freeze the plasmashell process in under a minute with this script:

#!/usr/bin/env python3
from time import sleep
from pydbus import SessionBus
from gi.repository import GLib
from PIL import Image
import sys
import string
import secrets


def random_string(length=64):
    alphabet = string.ascii_letters + string.digits

    return "".join(secrets.choice(alphabet) for _ in range(length))


# Load and prepare the image
try:
    img = Image.open("cover.png").convert("RGBA")
except Exception as e:
    print("Failed to load image 'cover.png':", e)
    sys.exit(1)

# Ensure image is exactly 640x640
if img.size != (640, 640):
    print("Image must be 640x640 pixels.")
    sys.exit(1)

width, height = img.size
channels = 4  # RGBA
rowstride = width * channels
bits_per_sample = 8
has_alpha = True
data = img.tobytes()

# Construct image-data struct
image_data = GLib.Variant(
    "(iiibiiay)",
    (
        width,
        height,
        rowstride,
        has_alpha,
        bits_per_sample,
        channels,
        GLib.Variant("ay", data),
    ),
)
# Construct hints
hints = {
    "sender-pid": GLib.Variant("x", 2),
    "desktop-entry": GLib.Variant("s", "com.mastermindzh.tidal-hifi"),
    "urgency": GLib.Variant("y", 1),
    "image-data": image_data,
    "resident": GLib.Variant("b", True),
}

# Connect to D-Bus
bus = SessionBus()
notifications = bus.get(".Notifications", "/org/freedesktop/Notifications")

while True:
    # Send notification
    notifications.Notify(
        "tidal-hifi",  # app_name
        0,  # replaces_id
        "",  # app_icon
        random_string(),  # summary
        random_string(),  # body
        ["default", "View"],  # actions
        hints,  # hints dict
        -1,  # expire_timeout (in ms)
    )
    sleep(1)

Some strings in the script were extracted from the intercepted D-Bus message. I wanted to be as close to the original message as possible. They really don’t matter for this bug.

But I think it has something to do with the image data which is about 410 kB in size when loaded into memory. Multiplied by the number of messages this could introduce unintended side-effects.

1 Like

That is a great starting point for a bug report!

Should make it relatively easy to reproduce and allows experimentation.

Product “plasmashell”, component “Notifications” sound the most appropriate to me

Now that you mention this, when my music player posts a new notification, it adds a small thumbnail with the album cover.

I am experiencing the same issue. After a certain uptime all apps i try to launch freeze the plasma UI completely with the same message in journalctl and a delayed notification. Because of this i reinstalled my OS but the issue still presists (i switched from vanilla Arch linux to CachyOS so the plasma version is still the same).
Also on my new system i never enabled file indexing so i thing an issue with baloo can be ruled out.
It’s really weird, because it happens with every app i try to launch, even if they don’t send any notification right away. After i did some research into that and found the following in journalctl | grep -i dolphin:

Jul 24 16:34:47 teilchenbeschleuniger systemd[1298]: Started Dolphin - File Manager.
Jul 24 16:34:50 teilchenbeschleuniger systemd[1298]: app-org.kde.dolphin@f186462920eb4623bd490a9536c0c887.service: Consumed 602ms CPU time, 86.1M memory peak.
Jul 24 16:35:12 teilchenbeschleuniger plasmashell[2076]: kf.kio.gui: Failed to launch process as service: "app-org.kde.dolphin@f186462920eb4623bd490a9536c0c887.service" "org.freedesktop.DBus.Error.NoReply" "Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken."

This was when i started and then closed dolphin. As you can see there is a 25 Second delay every time between the Started Dolphin and the error, in that time the plasma UI (the application launcher, panels etc.) are completely frozen, however applications that are already running, run fine and after i get that notification Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. the app also runs fine. Adding to that i also have the issue that was mentioned @0x7FFF that a music player posting a notification freezes.

My System:

Operating System: CachyOS Linux 
KDE Plasma Version: 6.4.3
KDE Frameworks Version: 6.16.0
Qt Version: 6.9.1
Kernel Version: 6.15.7-3-cachyos (64-bit)
Graphics Platform: Wayland
Processors: 32 × AMD Ryzen 9 7950X 16-Core Processor
Memory: 32 GiB of RAM (30,5 GiB usable)
Graphics Processor 1: AMD Radeon RX 6750 XT
Graphics Processor 2: AMD Radeon Graphics
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7D75
System Version: 1.0

Can confirm that. I looked at dbus-monitor "interface=org.freedesktop.Notifications" >> log.txt and the log size rose very fast using your script and plasma froze after some time. Maybe there is a memory issue in the notification-image rendering code ?

1 Like

I have created a bug ticket in the KDE bug tracker. Let’s see if the developers can confirm that there is an issue.

2 Likes

I fixed the bug, should be gone in the next version :slight_smile:

3 Likes

Very nice! Thank you for your efforts.

1 Like

Thank you so much!

1 Like