The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8298

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Can end up calling close() on the chDisconnect channel multiple times if called concurrently.

Fixes #8294

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 32fbbdcc9ddd9738b1eff6935e496d2d31ff6da1 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@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.parr...@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)
 }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to