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 the deadlock caused by the ImagePullDeleteLock #836

Merged
merged 3 commits into from
Jun 9, 2017
Merged
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions agent/engine/docker_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ func (imageManager *dockerImageManager) performPeriodicImageCleanup(ctx context.
}

func (imageManager *dockerImageManager) removeUnusedImages() {
seelog.Debug("Attempting to obtain ImagePullDeleteLock for removing images")
ImagePullDeleteLock.Lock()
seelog.Debug("Obtained ImagePullDeleteLock for removing images")
defer seelog.Debug("Released ImagePullDeleteLock after removing images")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe group these statements in an anonymous function so its easier to see the order of execution?

defer func() { ... }

defer ImagePullDeleteLock.Unlock()

seelog.Infof("Begin building map of eligible unused images for deletion")
imageManager.updateLock.Lock()
defer imageManager.updateLock.Unlock()
Expand All @@ -292,11 +298,6 @@ func (imageManager *dockerImageManager) removeUnusedImages() {
}

func (imageManager *dockerImageManager) removeLeastRecentlyUsedImage() error {
seelog.Debug("Attempting to obtain ImagePullDeleteLock for removing images")
ImagePullDeleteLock.Lock()
seelog.Debug("Obtained ImagePullDeleteLock for removing images")
defer seelog.Debug("Released ImagePullDeleteLock after removing images")
defer ImagePullDeleteLock.Unlock()
leastRecentlyUsedImage := imageManager.getUnusedImageForDeletion()
if leastRecentlyUsedImage == nil {
return fmt.Errorf("No more eligible images for deletion")
Expand Down