[lxc-devel] [lxd/master] lxd/containers: Fix race condition in shutdown

stgraber on Github lxc-bot at linuxcontainers.org
Fri Dec 15 04:39:58 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20171215/41665c67/attachment.bin>
-------------- next part --------------
From edbf30afd0af16b8e8d3aca33247d2652e29db4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 14 Dec 2017 23:39:04 -0500
Subject: [PATCH] lxd/containers: Fix race condition in shutdown
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #4102

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/containers.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lxd/containers.go b/lxd/containers.go
index 92cb6d96d..cfabfc503 100644
--- a/lxd/containers.go
+++ b/lxd/containers.go
@@ -209,9 +209,6 @@ func containersShutdown(s *state.State) error {
 	for _, c := range containers {
 		priority, _ := strconv.Atoi(c.ExpandedConfig()["boot.stop.priority"])
 
-		// Record the current state
-		lastState := c.State()
-
 		// Enforce shutdown priority
 		if priority != lastPriority {
 			lastPriority = priority
@@ -220,8 +217,11 @@ func containersShutdown(s *state.State) error {
 			wg.Wait()
 		}
 
+		// Record the current state
+		lastState := c.State()
+
 		// Stop the container
-		if c.IsRunning() {
+		if lastState != "BROKEN" && lastState != "STOPPED" {
 			// Determinate how long to wait for the container to shutdown cleanly
 			var timeoutSeconds int
 			value, ok := c.ExpandedConfig()["boot.host_shutdown_timeout"]


More information about the lxc-devel mailing list