diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 524d67b6ca..d89d45911a 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -122,7 +122,6 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta buf := new(unix.Statfs_t) err := unix.Statfs(rootfsFilePath(labels.mountPoint), buf) - stuckMountsMtx.Lock() close(success) if err != nil { @@ -155,11 +154,12 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg case <-success: // Success // If the mount has been marked as stuck, unmark it and log it's recovery. + stuckMountsMtx.Lock() + defer stuckMountsMtx.Unlock() if _, ok := stuckMounts[mountPoint]; ok { level.Debug(logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", mountPoint) delete(stuckMounts, mountPoint) } - stuckMountsMtx.Unlock() case <-mountCheckTimer.C: // Timed out, mark mount as stuck stuckMountsMtx.Lock() @@ -171,7 +171,6 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg level.Debug(logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", mountPoint) delete(stuckMounts, mountPoint) } - stuckMountsMtx.Unlock() default: level.Debug(logger).Log("msg", "Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint) stuckMounts[mountPoint] = struct{}{}