From fbc23548b9ec9efc509f5957773e6fe383202aa6 Mon Sep 17 00:00:00 2001 From: jordy1024 <58173714+jordy1024@users.noreply.github.com> Date: Sun, 24 Oct 2021 18:48:57 +0800 Subject: [PATCH] Fix timer GC delays in the Linux filesystem collector (#2169) Use `time.NewTimer()` and explicit `Stop()` to avoid memory bloat / GC problems with `time.After()` in the Linux filesystem collector timeout handling. Signed-off-by: bawenmao --- collector/filesystem_linux.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index af60d2e6..4853192c 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -122,10 +122,12 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { // then the watcher does nothing. If instead the timeout is reached, the // mount point that is being watched is marked as stuck. func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logger) { + mountCheckTimer := time.NewTimer(*mountTimeout) + defer mountCheckTimer.Stop() select { case <-success: // Success - case <-time.After(*mountTimeout): + case <-mountCheckTimer.C: // Timed out, mark mount as stuck stuckMountsMtx.Lock() select {