Skip to content

Commit

Permalink
Fix timer GC delays in the Linux filesystem collector (#2169)
Browse files Browse the repository at this point in the history
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 <bawenmao@sogou-inc.com>
  • Loading branch information
jordy1024 authored Oct 24, 2021
1 parent 863e737 commit fbc2354
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion collector/filesystem_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fbc2354

Please sign in to comment.