Browse code

Fix race between container cleanup and inspect/ps

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>

Alexandr Morozov authored on 2014/08/14 20:51:31
Showing 1 changed files
... ...
@@ -103,8 +103,17 @@ func (m *containerMonitor) Start() error {
103 103
 		exitStatus int
104 104
 	)
105 105
 
106
+	// this variable indicates that we under container.Lock
107
+	underLock := true
108
+
106 109
 	// ensure that when the monitor finally exits we release the networking and unmount the rootfs
107
-	defer m.Close()
110
+	defer func() {
111
+		if !underLock {
112
+			m.container.Lock()
113
+			defer m.container.Unlock()
114
+		}
115
+		m.Close()
116
+	}()
108 117
 
109 118
 	// reset the restart count
110 119
 	m.container.RestartCount = -1
... ...
@@ -136,6 +145,9 @@ func (m *containerMonitor) Start() error {
136 136
 			log.Errorf("Error running container: %s", err)
137 137
 		}
138 138
 
139
+		// here container.Lock is already lost
140
+		underLock = false
141
+
139 142
 		m.resetMonitor(err == nil && exitStatus == 0)
140 143
 
141 144
 		if m.shouldRestart(exitStatus) {