Bug 507883 - ksgrd_network_helper hangs on system shutdown
Summary: ksgrd_network_helper hangs on system shutdown
Status: RESOLVED FIXED
Alias: None
Product: plasma-systemmonitor
Classification: Applications
Component: general (other bugs)
Version First Reported In: 6.4.3
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: KSysGuard Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-05 06:01 UTC by Alex
Modified: 2025-08-11 13:20 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.4.5
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2025-08-05 06:01:06 UTC
SUMMARY
When running the default plasma-systemmonitor overview page, the system will hang on shutdown / restart for varying amounts of time, sometimes long enough to hit the SIGKILL timeout.

Example log of the issue:
Aug 04 17:22:02 systemd[1174]: Started System Monitor.
Aug 04 17:34:06 systemd[1174]: Stopping System Monitor...
Aug 04 17:35:36 systemd[1174]: app-org.kde.plasma\x2dsystemmonitor@a797899b4b96428aa30f8a08fee87e88.service: State 'stop-sigterm' timed out. Killing.
Aug 04 17:35:36 systemd[1174]: app-org.kde.plasma\x2dsystemmonitor@a797899b4b96428aa30f8a08fee87e88.service: Killing process 5467 (ksgrd_network_h) with signal SIGKILL.
Aug 04 17:35:36 systemd[1174]: app-org.kde.plasma\x2dsystemmonitor@a797899b4b96428aa30f8a08fee87e88.service: Killing process 5474 (ksgrd_network_h) with signal SIGKILL.
Aug 04 17:35:36 systemd[1174]: app-org.kde.plasma\x2dsystemmonitor@a797899b4b96428aa30f8a08fee87e88.service: Failed with result 'timeout'.
Aug 04 17:35:36 systemd[1174]: Stopped System Monitor.
Aug 04 17:35:36 systemd[1174]: app-org.kde.plasma\x2dsystemmonitor@a797899b4b96428aa30f8a08fee87e88.service: Consumed 31.842s CPU time, 125.4M memory peak.

STEPS TO REPRODUCE
1. Start System Monitor
2. Issue system shutdown or restart

OBSERVED RESULT
System shutdown varies wildly between a few seconds to over 90 seconds.

EXPECTED RESULT
System shutdown consistently occurs within a few seconds.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: 6.15.9-arch1-1
KDE Plasma Version: 6.4.3
KDE Frameworks Version: 6.16.0
Qt Version: 6.9.1

ADDITIONAL INFORMATION
After examining the source, it looks like the issue probably lies in Capture::nextPacket(). This function will block indefinitely until the next network packet is received, with no way to interrupt at program exit. This means that even on process shutdown, the network helper will block until any TCP/UDP traffic is received (at which point it will see that m_running is now false, and will join the thread). Assuming that network activity is minimal to nonexistent on system shutdown, this could block for an arbitrary amount of time, instead of exiting gracefully.
Comment 1 Bug Janitor Service 2025-08-07 10:14:56 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/libksysguard/-/merge_requests/433
Comment 2 Arjen Hiemstra 2025-08-09 11:06:19 UTC
Git commit 53753cf29ffcbfb56ecbcabf361af23b469609e6 by Arjen Hiemstra.
Committed on 09/08/2025 at 11:03.
Pushed by ahiemstra into branch 'master'.

processcore: Explicitly stop capturing packets on network helper terminate

In some cases, we may end up in a situation where we're terminating with
low or no network traffic. In such a case, we would block indefinitely
since there was no mechanism to notify `Capture::nextPacket()` that we
want to terminate.

This changes things so that we explicitly call `stop()` when the main
thread quits, which closes the pcap source and signals the wait
condition in Capture that we should no longer wait.

M  +28   -8    processcore/plugins/network/helper/Capture.cpp
M  +2    -0    processcore/plugins/network/helper/Capture.h
M  +2    -0    processcore/plugins/network/helper/main.cpp

https://invent.kde.org/plasma/libksysguard/-/commit/53753cf29ffcbfb56ecbcabf361af23b469609e6
Comment 3 Arjen Hiemstra 2025-08-11 12:45:41 UTC
Git commit f534a5b9d5f2beced22f747b72ca110e5917b117 by Arjen Hiemstra.
Committed on 11/08/2025 at 08:24.
Pushed by ahiemstra into branch 'Plasma/6.4'.

processcore: Explicitly stop capturing packets on network helper terminate

In some cases, we may end up in a situation where we're terminating with
low or no network traffic. In such a case, we would block indefinitely
since there was no mechanism to notify `Capture::nextPacket()` that we
want to terminate.

This changes things so that we explicitly call `stop()` when the main
thread quits, which closes the pcap source and signals the wait
condition in Capture that we should no longer wait.


(cherry picked from commit 53753cf29ffcbfb56ecbcabf361af23b469609e6)

Co-authored-by: Arjen Hiemstra <ahiemstra@heimr.nl>

M  +28   -8    processcore/plugins/network/helper/Capture.cpp
M  +2    -0    processcore/plugins/network/helper/Capture.h
M  +2    -0    processcore/plugins/network/helper/main.cpp

https://invent.kde.org/plasma/libksysguard/-/commit/f534a5b9d5f2beced22f747b72ca110e5917b117