Browse code

Fix some issues with locking on the container

- Fix OOM event updating healthchecks and persisting container state
without locks
- Fix healthchecks being updated without locks on container stop

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2017/11/15 10:59:40
Showing 3 changed files
... ...
@@ -64,6 +64,8 @@ func (daemon *Daemon) killWithSignal(container *containerpkg.Container, sig int)
64 64
 	container.Lock()
65 65
 	defer container.Unlock()
66 66
 
67
+	daemon.stopHealthchecks(container)
68
+
67 69
 	if !container.Running {
68 70
 		return errNotRunning(container.ID)
69 71
 	}
... ...
@@ -39,10 +39,14 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
39 39
 		if runtime.GOOS == "windows" {
40 40
 			return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
41 41
 		}
42
+
43
+		c.Lock()
44
+		defer c.Unlock()
42 45
 		daemon.updateHealthMonitor(c)
43 46
 		if err := c.CheckpointTo(daemon.containersReplica); err != nil {
44 47
 			return err
45 48
 		}
49
+
46 50
 		daemon.LogContainerEvent(c, "oom")
47 51
 	case libcontainerd.EventExit:
48 52
 		if int(ei.Pid) == c.Pid {
... ...
@@ -43,8 +43,6 @@ func (daemon *Daemon) containerStop(container *containerpkg.Container, seconds i
43 43
 		return nil
44 44
 	}
45 45
 
46
-	daemon.stopHealthchecks(container)
47
-
48 46
 	stopSignal := container.StopSignal()
49 47
 	// 1. Send a stop signal
50 48
 	if err := daemon.killPossiblyDeadProcess(container, stopSignal); err != nil {