Browse code

Check if the container is running if no event

When there is no event for the container it can happen because of a
crash and the container state on the persistent disk will have a
mismatch between what was in `/run` ( machine crash ).

This situation will create an unkillable container in docker because
containerd does not see it and it is not running but docker thinks it is
and you cannot tell it anything different.

This fixes the issue by checking if containerd has the container running
if we do not have an event instead of just returning.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>

Michael Crosby authored on 2016/07/28 01:21:13
Showing 1 changed files
... ...
@@ -505,12 +505,20 @@ func (clnt *client) Restore(containerID string, options ...CreateOption) error {
505 505
 			return err
506 506
 		}
507 507
 
508
-		// If ev is nil, then we already consumed all the event of the
509
-		// container, included the "exit" one.
510
-		// Thus we return to avoid overriding the Exit Code.
511 508
 		if ev == nil {
512
-			logrus.Warnf("libcontainerd: restore was called on a fully synced container (%s)", containerID)
513
-			return nil
509
+			if _, err := clnt.getContainer(containerID); err == nil {
510
+				// If ev is nil and the container is running in containerd,
511
+				// we already consumed all the event of the
512
+				// container, included the "exit" one.
513
+				// Thus we return to avoid overriding the Exit Code.
514
+				logrus.Warnf("libcontainerd: restore was called on a fully synced container (%s)", containerID)
515
+				return nil
516
+			}
517
+			// the container is not running so we need to fix the state within docker
518
+			ev = &containerd.Event{
519
+				Type:   StateExit,
520
+				Status: 1,
521
+			}
514 522
 		}
515 523
 
516 524
 		// get the exit status for this container