Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a logmon goroutine and memory leak #11261

Merged
merged 4 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11261.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
client: Fixed a memory leak in log collector when tasks restart
```
16 changes: 11 additions & 5 deletions client/logmon/logging/rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewFileRotator(path string, baseFile string, maxFiles int,
flushTicker: time.NewTicker(bufferFlushDuration),
logger: logger,
purgeCh: make(chan struct{}, 1),
doneCh: make(chan struct{}, 1),
doneCh: make(chan struct{}),
}

if err := rotator.lastFile(); err != nil {
Expand Down Expand Up @@ -237,8 +237,14 @@ func (f *FileRotator) createFile() error {
// flushPeriodically flushes the buffered writer every 100ms to the underlying
// file
func (f *FileRotator) flushPeriodically() {
for range f.flushTicker.C {
f.flushBuffer()
for {
select {
case <-f.flushTicker.C:
f.flushBuffer()
case <-f.doneCh:
return
}

}
}

Expand All @@ -251,9 +257,9 @@ func (f *FileRotator) Close() error {
f.flushTicker.Stop()
f.flushBuffer()

// Stop the purge go routine
// Stop the go routines
if !f.closed {
f.doneCh <- struct{}{}
close(f.doneCh)
close(f.purgeCh)
f.closed = true
f.currentFile.Close()
Expand Down
Loading