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

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: Stéphane Graber <stgra...@ubuntu.com>
From 9b5f28994b9529a89893f15b297b779624b74104 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com>
Date: Thu, 18 Jul 2019 15:21:36 -0400
Subject: [PATCH] lxd/cluster: Use goroutine to avoid cgo crash
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
---
 lxd/cluster/gateway.go | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/lxd/cluster/gateway.go b/lxd/cluster/gateway.go
index 4a760c9a98..d194c10e91 100644
--- a/lxd/cluster/gateway.go
+++ b/lxd/cluster/gateway.go
@@ -46,15 +46,29 @@ func NewGateway(db *db.Node, cert *shared.CertInfo, options 
...Option) (*Gateway
        }
 
        gateway := &Gateway{
-               db:        db,
-               cert:      cert,
-               options:   o,
-               ctx:       ctx,
-               cancel:    cancel,
-               upgradeCh: make(chan struct{}, 16),
-               acceptCh:  make(chan net.Conn),
-               store:     &dqliteServerStore{},
-       }
+               db:          db,
+               cert:        cert,
+               options:     o,
+               ctx:         ctx,
+               cancel:      cancel,
+               upgradeCh:   make(chan struct{}, 16),
+               acceptCh:    make(chan net.Conn),
+               heartbeatCh: make(chan error, 1),
+               store:       &dqliteServerStore{},
+       }
+
+       // Handler for dqlite triggered hearbeats
+       go func() {
+               for {
+                       select {
+                       case <-gateway.ctx.Done():
+                               return
+                       case <-gateway.heartbeatCh:
+                               gateway.heartbeat(gateway.ctx, true)
+                               continue
+                       }
+               }
+       }()
 
        err := gateway.init()
        if err != nil {
@@ -104,6 +118,7 @@ type Gateway struct {
        upgradeTriggered bool
 
        // Used for the heartbeat handler
+       heartbeatCh       chan error
        Cluster           *db.Cluster
        HeartbeatNodeHook func(*APIHeartbeat)
 
@@ -820,7 +835,7 @@ func (g *Gateway) watchFunc(oldState int, newState int) {
                logger.Info("Node was elected as dqlite leader", log.Ctx{"id": 
g.raft.info.ID, "address": g.raft.info.Address})
 
                // Trigger an immediate full hearbeat run
-               go g.heartbeat(g.ctx, true)
+               g.heartbeatCh <- nil
        }
 }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to