Merge pull request #767 from vmarmol/fix-leak

Remove stats from cache when container is destroyed
This commit is contained in:
Rohit Jnagal 2015-06-10 08:20:44 -07:00
commit a36554fc80
3 changed files with 15 additions and 0 deletions

4
cache/cache.go vendored
View File

@ -17,8 +17,12 @@ package cache
import info "github.com/google/cadvisor/info/v1"
type Cache interface {
// Add a ContainerStats for the specified container.
AddStats(ref info.ContainerReference, stats *info.ContainerStats) error
// Remove all cached information for the specified container.
RemoveContainer(containerName string) error
// Read most recent stats. numStats indicates max number of stats
// returned. The returned stats must be consecutive observed stats. If
// numStats < 0, then return all stats stored in the storage. The

View File

@ -118,6 +118,13 @@ func (self *InMemoryCache) Close() error {
return nil
}
func (self *InMemoryCache) RemoveContainer(containerName string) error {
self.lock.Lock()
delete(self.containerCacheMap, containerName)
self.lock.Unlock()
return nil
}
func New(
maxAge time.Duration,
backend storage.StorageDriver,

View File

@ -81,6 +81,10 @@ func (c *containerData) Start() error {
}
func (c *containerData) Stop() error {
err := c.memoryCache.RemoveContainer(c.info.Name)
if err != nil {
return err
}
c.stop <- true
return nil
}