[lxc-devel] [lxd/master] lxd/storgage/locking/lock: Fixes concurrent access race to map
tomponline on Github
lxc-bot at linuxcontainers.org
Wed Jan 29 11:42:39 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 492 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200129/71810861/attachment.bin>
-------------- next part --------------
From 311825ba29d8a6d9551004441e992653c3df0120 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Wed, 29 Jan 2020 11:41:09 +0000
Subject: [PATCH] lxd/storgage/locking/lock: Fixes concurrent access race to
map
There is a race modifying the lock map with a new lock channel for a named lock which causes hangs during high load benchmarks.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/locking/lock.go | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lxd/storage/locking/lock.go b/lxd/storage/locking/lock.go
index bafdcecddb..727974484c 100644
--- a/lxd/storage/locking/lock.go
+++ b/lxd/storage/locking/lock.go
@@ -27,12 +27,12 @@ func Lock(poolName string, volType string, volName string) func() {
// Get exclusive access to the map and see if there is already an operation ongoing.
ongoingOperationMapLock.Lock()
waitCh, ok := ongoingOperationMap[lockID]
- ongoingOperationMapLock.Unlock()
if !ok {
// No ongoing operation, create a new channel to indicate our new operation.
waitCh = make(chan struct{})
ongoingOperationMap[lockID] = waitCh
+ ongoingOperationMapLock.Unlock()
// Return a function that will complete the operation.
return func() {
@@ -59,6 +59,7 @@ func Lock(poolName string, volType string, volName string) func() {
// An existing operation is ongoing, lets wait for that to finish and then try
// to get exlusive access to create a new operation again.
+ ongoingOperationMapLock.Unlock()
<-waitCh
}
}
More information about the lxc-devel
mailing list