[lxc-devel] [lxd/master] list: fix concurrent read/write

tych0 on Github lxc-bot at linuxcontainers.org
Tue Jul 19 15:27:30 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1802 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160719/8a87570e/attachment.bin>
-------------- next part --------------
From 7d755a934690734f17d3c7eb661e190d0d06a7ec Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Tue, 19 Jul 2016 09:25:50 -0600
Subject: [PATCH] list: fix concurrent read/write

We can't concurrently write, but we can't concurrently read either, so let's
extend the lock duration.

Closes #2183

fatal error: concurrent map read and map write

goroutine 1 [running]:
runtime.throw(0x9cd180, 0x21)
	/usr/lib/go-1.6/src/runtime/panic.go:530 +0x90 fp=0xc8200f0fa8 sp=0xc8200f0f90
runtime.mapaccess2_faststr(0x808280, 0xc8201db140, 0xc8201b43d0, 0xb, 0x0, 0xdbf920)
	/usr/lib/go-1.6/src/runtime/hashmap_fast.go:307 +0x5b fp=0xc8200f1008 sp=0xc8200f0fa8
main.(*listCmd).listContainers(0xc82000be30, 0xc8200d0700, 0xc8201e0000, 0x32, 0x50, 0xc820011a50, 0x1, 0x1, 0xc82008ff00, 0x3, ...)
	/build/lxd-ma7bPQ/lxd-2.0.2/obj-x86_64-linux-gnu/src/github.com/lxc/lxd/lxc/list.go:254 +0x651 fp=0xc8200f1750 sp=0xc8200f1008
main.(*listCmd).run(0xc82000be30, 0xc8200f2030, 0x0, 0x0, 0x0, 0x0, 0x0)
	/build/lxd-ma7bPQ/lxd-2.0.2/obj-x86_64-linux-gnu/src/github.com/lxc/lxd/lxc/list.go:401 +0x1324 fp=0xc8200f1ae8 sp=0xc8200f1750
main.run(0x0, 0x0)
	/build/lxd-ma7bPQ/lxd-2.0.2/obj-x86_64-linux-gnu/src/github.com/lxc/lxd/lxc/main.go:151 +0x1098 fp=0xc8200f1df0 sp=0xc8200f1ae8
main.main()
	/build/lxd-ma7bPQ/lxd-2.0.2/obj-x86_64-linux-gnu/src/github.com/lxc/lxd/lxc/main.go:23 +0x3a fp=0xc8200f1f40 sp=0xc8200f1df0
runtime.main()
	/usr/lib/go-1.6/src/runtime/proc.go:188 +0x2b0 fp=0xc8200f1f90 sp=0xc8200f1f40
runtime.goexit()
	/usr/lib/go-1.6/src/runtime/asm_amd64.s:1998 +0x1 fp=0xc8200f1f98 sp=0xc8200f1f90

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxc/list.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxc/list.go b/lxc/list.go
index a4863c3..b8fbffa 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -283,12 +283,12 @@ func (c *listCmd) listContainers(d *lxd.Client, cinfos []shared.ContainerInfo, f
 	for _, cInfo := range cinfos {
 		for _, column := range columns {
 			if column.NeedsState && cInfo.IsActive() {
+				cStatesLock.Lock()
 				_, ok := cStates[cInfo.Name]
 				if ok {
 					continue
 				}
 
-				cStatesLock.Lock()
 				cStates[cInfo.Name] = nil
 				cStatesLock.Unlock()
 
@@ -296,12 +296,12 @@ func (c *listCmd) listContainers(d *lxd.Client, cinfos []shared.ContainerInfo, f
 			}
 
 			if column.NeedsSnapshots {
+				cSnapshotsLock.Lock()
 				_, ok := cSnapshots[cInfo.Name]
 				if ok {
 					continue
 				}
 
-				cSnapshotsLock.Lock()
 				cSnapshots[cInfo.Name] = nil
 				cSnapshotsLock.Unlock()
 


More information about the lxc-devel mailing list