From 086cf3ab125d1c423d07ef877846fd8c1e01f3ac Mon Sep 17 00:00:00 2001
From: lujingxiao <lujingxiao@huawei.com>
Date: Mon, 11 Feb 2019 18:44:50 +0800
Subject: [PATCH 096/111] pause:  check tasks before updateCgroups

reason: In the Pause of dockerd, it updateCgroups first, then
check tasks file if any tasks in the cgroups. We should check the
tasks file before updateCgroups

Change-Id: I7f30e314b3db9c50459d995bf071e01a47f359f0
Signed-off-by: lujingxiao <lujingxiao@huawei.com>
---
 components/engine/daemon/freezer/freezer.go | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/components/engine/daemon/freezer/freezer.go b/components/engine/daemon/freezer/freezer.go
index cd8b3513d7..a0ef299852 100644
--- a/components/engine/daemon/freezer/freezer.go
+++ b/components/engine/daemon/freezer/freezer.go
@@ -122,10 +122,6 @@ func (f *freezer) Pause() error {
 	f.Lock()
 	defer f.Unlock()
 
-	if err := f.updateCgroup(string(configs.Frozen)); err != nil {
-		return err
-	}
-
 	tasks, err := readFile(f.path, "tasks")
 	if err != nil {
 		return fmt.Errorf("failed to check container cgroup task status: %v", err)
@@ -134,7 +130,8 @@ func (f *freezer) Pause() error {
 	if strings.TrimSpace(tasks) == "" {
 		return fmt.Errorf("error: no tasks running in freeze cgroup")
 	}
-	return nil
+
+	return f.updateCgroup(string(configs.Frozen))
 }
 
 // Resume will set the container to running state by writing freeze cgroup.
@@ -186,7 +183,7 @@ func (f *freezer) updateCgroup(state string) error {
 			}
 			newState, err := readFile(f.path, "freezer.state")
 			if err != nil {
-				return err
+				return fmt.Errorf("read freezer.state failed after write: %v", err)
 			}
 			if strings.TrimSpace(newState) == state {
 				return nil
-- 
2.17.1

