Skip to content

Commit 1cb2049

Browse files
author
Mahmood Ali
authored
Merge pull request #11261 from hashicorp/b-logmon-leak
Fix a logmon goroutine and memory leak
2 parents 88ff7f4 + 40c7720 commit 1cb2049

File tree

5 files changed

+142
-193
lines changed

5 files changed

+142
-193
lines changed

.changelog/11261.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
client: Fixed a memory leak in log collector when tasks restart
3+
```

client/logmon/logging/rotator.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func NewFileRotator(path string, baseFile string, maxFiles int,
7171
flushTicker: time.NewTicker(bufferFlushDuration),
7272
logger: logger,
7373
purgeCh: make(chan struct{}, 1),
74-
doneCh: make(chan struct{}, 1),
74+
doneCh: make(chan struct{}),
7575
}
7676

7777
if err := rotator.lastFile(); err != nil {
@@ -237,8 +237,14 @@ func (f *FileRotator) createFile() error {
237237
// flushPeriodically flushes the buffered writer every 100ms to the underlying
238238
// file
239239
func (f *FileRotator) flushPeriodically() {
240-
for range f.flushTicker.C {
241-
f.flushBuffer()
240+
for {
241+
select {
242+
case <-f.flushTicker.C:
243+
f.flushBuffer()
244+
case <-f.doneCh:
245+
return
246+
}
247+
242248
}
243249
}
244250

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

254-
// Stop the purge go routine
260+
// Stop the go routines
255261
if !f.closed {
256-
f.doneCh <- struct{}{}
262+
close(f.doneCh)
257263
close(f.purgeCh)
258264
f.closed = true
259265
f.currentFile.Close()

0 commit comments

Comments
 (0)