[lxc-devel] [lxd/master] QMP: Fix race in Disconnect
tomponline on Github
lxc-bot at linuxcontainers.org
Mon Jan 4 14:54:40 UTC 2021
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 473 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20210104/ee3b15a3/attachment.bin>
-------------- next part --------------
From 32fbbdcc9ddd9738b1eff6935e496d2d31ff6da1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Mon, 4 Jan 2021 14:53:24 +0000
Subject: [PATCH] lxd/instance/drivers/qmp: Fix race in Disconnect
Can end up calling close() on the chDisconnect channel multiple times if called concurrently.
Fixes #8294
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance/drivers/qmp/monitor.go | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/lxd/instance/drivers/qmp/monitor.go b/lxd/instance/drivers/qmp/monitor.go
index 00d2453ad0..72950e093c 100644
--- a/lxd/instance/drivers/qmp/monitor.go
+++ b/lxd/instance/drivers/qmp/monitor.go
@@ -171,16 +171,17 @@ func (m *Monitor) Wait() (chan struct{}, error) {
// Disconnect forces a disconnection from QEMU.
func (m *Monitor) Disconnect() {
+ // Remove from the map.
+ monitorsLock.Lock()
+ defer monitorsLock.Unlock()
+
// Stop all go routines and disconnect from socket.
if !m.disconnected {
close(m.chDisconnect)
+ m.disconnected = true
+ m.qmp.Disconnect()
}
- m.disconnected = true
- m.qmp.Disconnect()
- // Remove from the map.
- monitorsLock.Lock()
- defer monitorsLock.Unlock()
delete(monitors, m.path)
}
More information about the lxc-devel
mailing list