Skip to content

Commit

Permalink
Fix memory leak in task stats collector
Browse files Browse the repository at this point in the history
  • Loading branch information
angelcar committed Nov 8, 2021
1 parent 9ce81fb commit 4965b57
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions agent/stats/task_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ func newStatsTaskContainer(taskARN string, containerPID string, numberOfContaine
}, nil
}

func (task *StatsTask) StartStatsCollection() {
func (taskStat *StatsTask) StartStatsCollection() {
queueSize := int(config.DefaultContainerMetricsPublishInterval.Seconds() * 4)
task.StatsQueue = NewQueue(queueSize)
task.StatsQueue.Reset()
go task.collect()
taskStat.StatsQueue = NewQueue(queueSize)
taskStat.StatsQueue.Reset()
go taskStat.collect()
}

func (task *StatsTask) StopStatsCollection() {
task.Cancel()
func (taskStat *StatsTask) StopStatsCollection() {
taskStat.Cancel()
}

func (taskStat *StatsTask) collect() {
Expand Down Expand Up @@ -204,7 +204,7 @@ func linkStatsToDockerStats(netLinkStats *netlinklib.LinkStatistics, numberOfCon

func (taskStat *StatsTask) getAWSVPCNetworkStats() (<-chan *types.StatsJSON, <-chan error) {

errC := make(chan error)
errC := make(chan error, 1)
statsC := make(chan *dockerstats.StatsJSON)
if taskStat.TaskMetadata.NumberContainers > 0 {
go func() {
Expand Down Expand Up @@ -248,7 +248,11 @@ func (taskStat *StatsTask) getAWSVPCNetworkStats() (<-chan *types.StatsJSON, <-c
Read: time.Now(),
},
}
statsC <- dockerStats
select {
case <-taskStat.Ctx.Done():
return
case statsC <- dockerStats:
}
}
}()
}
Expand Down

0 comments on commit 4965b57

Please sign in to comment.