The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7421
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) === We need to do this since now we're leaving the endpoints open for a good part of the shutdown sequence, to allow for cluster membership adjustments. Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com>
From 23f555fc6a96cd364638a75af78991b4c74a5a3d Mon Sep 17 00:00:00 2001 From: Free Ekanayaka <free.ekanay...@canonical.com> Date: Mon, 25 May 2020 12:37:26 +0100 Subject: [PATCH] lxd/api: Fail requests made after shutdown has started We need to do this since now we're leaving the endpoints open for a good part of the shutdown sequence, to allow for cluster membership adjustments. Signed-off-by: Free Ekanayaka <free.ekanay...@canonical.com> --- lxd/api.go | 11 +++++++++++ lxd/daemon.go | 2 +- lxd/main_daemon.go | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lxd/api.go b/lxd/api.go index 0b95fe729a..16d1aeff21 100644 --- a/lxd/api.go +++ b/lxd/api.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "net/http" "net/url" "strings" @@ -80,6 +81,16 @@ func (s *lxdHttpServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { resp.Render(rw) return } + } else { + var isClosing bool + s.d.clusterMembershipMutex.RLock() + isClosing = s.d.clusterMembershipClosing + s.d.clusterMembershipMutex.RUnlock() + if isClosing { + resp := response.SmartError(fmt.Errorf("Shutting down")) + resp.Render(rw) + return + } } // OPTIONS request don't need any further processing diff --git a/lxd/daemon.go b/lxd/daemon.go index 5e5fceb630..47ef372f7f 100644 --- a/lxd/daemon.go +++ b/lxd/daemon.go @@ -97,7 +97,7 @@ type Daemon struct { // Serialize changes to cluster membership (joins, leaves, role // changes). - clusterMembershipMutex sync.Mutex + clusterMembershipMutex sync.RWMutex clusterMembershipClosing bool // Prevent further rebalances } diff --git a/lxd/main_daemon.go b/lxd/main_daemon.go index d7761bd03c..e6ade1aac0 100644 --- a/lxd/main_daemon.go +++ b/lxd/main_daemon.go @@ -85,8 +85,8 @@ func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error { containersShutdown(s) networkShutdown(s) } else { - d.Kill() logger.Infof("Received '%s signal', exiting", sig) + d.Kill() } case <-d.shutdownChan:
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel