diff options
| author | Nikita Mochalov <Zamony@users.noreply.github.com> | 2023-08-10 01:30:36 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-09 15:30:36 -0700 |
| commit | e6a49dc5337bb73a6334647bb34a44570b3ef6d7 (patch) | |
| tree | 238a2b7e5ba2c80427cf7898e521e62b8bd8977e /weed/storage/disk_location.go | |
| parent | 3365468d0d683f61a915eebce06cc8c54ecd1dd6 (diff) | |
| download | seaweedfs-e6a49dc5337bb73a6334647bb34a44570b3ef6d7.tar.xz seaweedfs-e6a49dc5337bb73a6334647bb34a44570b3ef6d7.zip | |
Fix resource leaks (#4737)
* Fix division by zero
* Fix file handle leak
* Fix file handle leak
* Fix file handle leak
* Fix goroutine leak
Diffstat (limited to 'weed/storage/disk_location.go')
| -rw-r--r-- | weed/storage/disk_location.go | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 2ee1548a2..aa3f35eac 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -35,6 +35,7 @@ type DiskLocation struct { ecVolumesLock sync.RWMutex isDiskSpaceLow bool + closeCh chan struct{} } func GenerateDirUuid(dir string) (dirUuidString string, err error) { @@ -80,7 +81,17 @@ func NewDiskLocation(dir string, maxVolumeCount int32, minFreeSpace util.MinFree } location.volumes = make(map[needle.VolumeId]*Volume) location.ecVolumes = make(map[needle.VolumeId]*erasure_coding.EcVolume) - go location.CheckDiskSpace() + location.closeCh = make(chan struct{}) + go func() { + for { + select { + case <-location.closeCh: + return + case <-time.After(time.Minute): + location.CheckDiskSpace() + } + } + }() return location } @@ -384,6 +395,7 @@ func (l *DiskLocation) Close() { } l.ecVolumesLock.Unlock() + close(l.closeCh) return } @@ -420,26 +432,22 @@ func (l *DiskLocation) UnUsedSpace(volumeSizeLimit uint64) (unUsedSpace uint64) } func (l *DiskLocation) CheckDiskSpace() { - for { - if dir, e := filepath.Abs(l.Directory); e == nil { - s := stats.NewDiskStatus(dir) - stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "all").Set(float64(s.All)) - stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "used").Set(float64(s.Used)) - stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "free").Set(float64(s.Free)) - - isLow, desc := l.MinFreeSpace.IsLow(s.Free, s.PercentFree) - if isLow != l.isDiskSpaceLow { - l.isDiskSpaceLow = !l.isDiskSpaceLow - } - - logLevel := glog.Level(4) - if l.isDiskSpaceLow { - logLevel = glog.Level(0) - } + if dir, e := filepath.Abs(l.Directory); e == nil { + s := stats.NewDiskStatus(dir) + stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "all").Set(float64(s.All)) + stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "used").Set(float64(s.Used)) + stats.VolumeServerResourceGauge.WithLabelValues(l.Directory, "free").Set(float64(s.Free)) + + isLow, desc := l.MinFreeSpace.IsLow(s.Free, s.PercentFree) + if isLow != l.isDiskSpaceLow { + l.isDiskSpaceLow = !l.isDiskSpaceLow + } - glog.V(logLevel).Infof("dir %s %s", dir, desc) + logLevel := glog.Level(4) + if l.isDiskSpaceLow { + logLevel = glog.Level(0) } - time.Sleep(time.Minute) - } + glog.V(logLevel).Infof("dir %s %s", dir, desc) + } } |
