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

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) ===
Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 7eccacb73fa8a0b6ac1d3237d61abec8b8e4eb3d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 16 Jun 2020 15:53:14 +0100
Subject: [PATCH] lxd/cluster/heartbeat: Fix race in HeartbeatNode

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/cluster/heartbeat.go | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lxd/cluster/heartbeat.go b/lxd/cluster/heartbeat.go
index b43be4d9b1..5c7474ce32 100644
--- a/lxd/cluster/heartbeat.go
+++ b/lxd/cluster/heartbeat.go
@@ -125,7 +125,7 @@ func (hbState *APIHeartbeat) Send(ctx context.Context, cert 
*shared.CertInfo, lo
 
                err := HeartbeatNode(ctx, address, cert, heartbeatData)
                if err == nil {
-                       hbState.Lock()
+                       heartbeatData.Lock()
                        // Ensure only update nodes that exist in Members 
already.
                        hbNode, existing := hbState.Members[nodeID]
                        if !existing {
@@ -135,8 +135,8 @@ func (hbState *APIHeartbeat) Send(ctx context.Context, cert 
*shared.CertInfo, lo
                        hbNode.LastHeartbeat = time.Now()
                        hbNode.Online = true
                        hbNode.updated = true
-                       hbState.Members[nodeID] = hbNode
-                       hbState.Unlock()
+                       heartbeatData.Members[nodeID] = hbNode
+                       heartbeatData.Unlock()
                        logger.Debugf("Successful heartbeat for %s", address)
                } else {
                        logger.Debugf("Failed heartbeat for %s: %v", address, 
err)
@@ -365,7 +365,9 @@ func HeartbeatNode(taskCtx context.Context, address string, 
cert *shared.CertInf
        }
 
        buffer := bytes.Buffer{}
+       heartbeatData.Lock()
        err = json.NewEncoder(&buffer).Encode(heartbeatData)
+       heartbeatData.Unlock()
        if err != nil {
                return err
        }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to