Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

fix(hostmetrics): skip disk probes for cancelled collections

pulse-triage[bot]a0211b8242c6
diff --git a/internal/hostmetrics/collector.go b/internal/hostmetrics/collector.go
index 1a02e5d43e..785efb1586 100644
--- a/internal/hostmetrics/collector.go
+++ b/internal/hostmetrics/collector.go
@@ -100,6 +100,10 @@ type diskUsageCall struct {
// guardedDiskUsage bounds the wait for a mount probe and leaves at most one
// syscall in flight per mountpoint, even when reporting loops overlap.
func guardedDiskUsage(ctx context.Context, mountpoint string) (*godisk.UsageStat, error) {
+ // Do not admit potentially uninterruptible work for an expired collection.
+ if err := ctx.Err(); err != nil {
+ return nil, err
+ }
stuckDiskMounts.Lock()
call, loaded := stuckDiskMounts.calls[mountpoint]
if !loaded {
diff --git a/internal/hostmetrics/collector_stuck_mount_test.go b/internal/hostmetrics/collector_stuck_mount_test.go
index 3a6b0d4471..5e08bbcdc4 100644
--- a/internal/hostmetrics/collector_stuck_mount_test.go
+++ b/internal/hostmetrics/collector_stuck_mount_test.go
@@ -284,3 +284,37 @@ func TestGuardedDiskUsage_ConcurrentHealthyMounts(t *testing.T) {
}
}
}
+
+// A cancelled collection must not start a syscall which may ignore its context
+// and remain stuck in the kernel after the caller has already gone away.
+func TestGuardedDiskUsage_AlreadyCancelledDoesNotStartProbe(t *testing.T) {
+ const mount = "/test/already-cancelled"
+ origUsage := diskUsage
+ var calls atomic.Int32
+ diskUsage = func(context.Context, string) (*godisk.UsageStat, error) {
+ calls.Add(1)
+ return nil, nil
+ }
+ defer func() { diskUsage = origUsage }()
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+ _, err := guardedDiskUsage(ctx, mount)
+ // Wait for any incorrectly admitted probe to finish before restoring the
+ // shared stub; registry removal follows the syscall.
+ deadline := time.Now().Add(2 * time.Second)
+ for {
+ if _, ok := loadDiskUsageCall(mount); !ok {
+ break
+ }
+ if time.Now().After(deadline) {
+ t.Fatal("probe did not drain")
+ }
+ time.Sleep(time.Millisecond)
+ }
+ if err != context.Canceled {
+ t.Errorf("error = %v, want context.Canceled", err)
+ }
+ if got := calls.Load(); got != 0 {
+ t.Fatalf("cancelled collection started %d probes, want none", got)
+ }
+}