https://bugs.kde.org/show_bug.cgi?id=528227

            Bug ID: 528227
           Summary: Sensors stay subscribed when a client leaves the bus
                    before ksystemstats handles its subscribe call
    Classification: Frameworks and Libraries
           Product: ksystemstats
      Version First 6.8.2
       Reported In:
          Platform: NixOS
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: General
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

When a client sends subscribe and leaves the bus before ksystemstats handles
the call, its sensors stay subscribed until ksystemstats exits. On my NVIDIA
laptop this keeps `nvidia-smi dmon` running, so the dGPU does not
runtime-suspend.

Daemon::subscribe() calls m_serviceWatcher->addWatchedService(sender), but
QDBusServiceWatcher only reports names that unregister after that. When the
sender is already gone, onServiceDisconnected() never runs for it, and its
Client is never deleted. src/daemon.cpp is the same on master (abe3da27).

I ran this script in a private session bus with the ksystemstats 6.8.2 binary,
as `dbus-run-session -- bash repro.sh <path to ksystemstats>`:

```
#!/usr/bin/env bash
set -uo pipefail
bin=$1
svc=(org.kde.ksystemstats1 /org/kde/ksystemstats1 org.kde.ksystemstats1)
timeout 60 "$bin" --remain >/dev/null 2>&1 &
wrapper=$!
for _ in $(seq 50); do
  busctl --user status org.kde.ksystemstats1 >/dev/null 2>&1 && break
  sleep 0.2
done
dmon() {
  if ps -eo args= | grep -qE '^(/[^ ]*/)?nvidia-smi dmon'; then echo running;
else echo stopped; fi
}
echo "nvidia-smi dmon at start: $(dmon)"
busctl --user call "${svc[@]}" subscribe as 1 gpu/gpu0/usage
sleep 3
echo "1. busctl call subscribe (waits for the reply), then busctl exits. 3 s
later: $(dmon)"
sleep 7
echo "   10 s later: $(dmon)"
busctl --user --expect-reply=no call "${svc[@]}" subscribe as 1 gpu/gpu0/usage
sleep 3
echo "2. busctl --expect-reply=no call subscribe, so busctl exits at once. 3 s
later: $(dmon)"
sleep 27
echo "   30 s later: $(dmon)"
wait "$wrapper"
sleep 2
echo "after the daemon's 60 s timeout ended it: $(dmon)"
```

Two runs printed the same:

```
nvidia-smi dmon at start: stopped
1. busctl call subscribe (waits for the reply), then busctl exits. 3 s later:
stopped
   10 s later: stopped
2. busctl --expect-reply=no call subscribe, so busctl exits at once. 3 s later:
running
   30 s later: running
after the daemon's 60 s timeout ended it: stopped
```

With a build whose Daemon::subscribe() checks
connection().interface()->isServiceRegistered(sender) after addWatchedService()
and drops the client when the name is gone, step 2 also prints "stopped".

Is that check the right place for the fix? Bug 526594 has the same symptom from
a different cause (one client subscribing twice).

NixOS 26.11, Plasma 6.8.2, Frameworks 6.31.0, Qt 6.12.0, NVIDIA GeForce RTX
4070 Laptop GPU with runtime D3.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to