From e66feedd2f228b7e586b335626c5e166ab9f443c Mon Sep 17 00:00:00 2001 From: richardpen Date: Tue, 24 Jan 2017 23:48:57 +0000 Subject: [PATCH] Fixed a race condition that can cause agent panici --- agent/engine/image/types.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/agent/engine/image/types.go b/agent/engine/image/types.go index f7e038302a0..644d05c1630 100644 --- a/agent/engine/image/types.go +++ b/agent/engine/image/types.go @@ -14,6 +14,7 @@ package image import ( + "encoding/json" "fmt" "sync" "time" @@ -98,3 +99,18 @@ func (imageState *ImageState) RemoveContainerReference(container *api.Container) } return fmt.Errorf("Container reference is not found in the image state container: %s", container.String()) } + +func (imageState *ImageState) MarshalJSON() ([]byte, error) { + imageState.updateLock.Lock() + defer imageState.updateLock.Unlock() + + return json.Marshal(&struct { + Image *Image + PulledAt time.Time + LastUsedAt time.Time + }{ + Image: imageState.Image, + PulledAt: imageState.PulledAt, + LastUsedAt: imageState.LastUsedAt, + }) +}