The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6442
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 b32ac8fbf31e4a976f24adc1c583d6469df6f879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Tue, 12 Nov 2019 10:27:06 -0800 Subject: [PATCH] client: Add Disconnect function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- client/connection.go | 7 ++++++- client/interfaces.go | 1 + client/lxd.go | 10 +++++++++- client/lxd_events.go | 1 + client/simplestreams.go | 5 +++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/client/connection.go b/client/connection.go index dde3e327a1..86cdcbaafb 100644 --- a/client/connection.go +++ b/client/connection.go @@ -7,9 +7,10 @@ import ( "path/filepath" "strings" + "gopkg.in/macaroon-bakery.v2/httpbakery" + "github.com/lxc/lxd/shared/logger" "github.com/lxc/lxd/shared/simplestreams" - "gopkg.in/macaroon-bakery.v2/httpbakery" ) // ConnectionArgs represents a set of common connection properties @@ -81,6 +82,7 @@ func ConnectLXDHTTP(args *ConnectionArgs, client *http.Client) (InstanceServer, httpHost: "https://custom.socket", httpProtocol: "custom", httpUserAgent: args.UserAgent, + chConnected: make(chan struct{}, 1), } // Setup the HTTP client @@ -119,6 +121,7 @@ func ConnectLXDUnix(path string, args *ConnectionArgs) (InstanceServer, error) { httpUnixPath: path, httpProtocol: "unix", httpUserAgent: args.UserAgent, + chConnected: make(chan struct{}, 1), } // Determine the socket path @@ -216,7 +219,9 @@ func httpsLXD(url string, args *ConnectionArgs) (InstanceServer, error) { httpProtocol: "https", httpUserAgent: args.UserAgent, bakeryInteractor: args.AuthInteractor, + chConnected: make(chan struct{}, 1), } + if args.AuthType == "candid" { server.RequireAuthenticated(true) } diff --git a/client/interfaces.go b/client/interfaces.go index 9dd9b7f5cf..fb954734f9 100644 --- a/client/interfaces.go +++ b/client/interfaces.go @@ -34,6 +34,7 @@ type RemoteOperation interface { type Server interface { GetConnectionInfo() (info *ConnectionInfo, err error) GetHTTPClient() (client *http.Client, err error) + Disconnect() } // The ImageServer type represents a read-only image server. diff --git a/client/lxd.go b/client/lxd.go index 02cf92b3fb..a99ca34cb5 100644 --- a/client/lxd.go +++ b/client/lxd.go @@ -22,7 +22,8 @@ import ( // ProtocolLXD represents a LXD API server type ProtocolLXD struct { - server *api.Server + server *api.Server + chConnected chan struct{} eventListeners []*EventListener eventListenersLock sync.Mutex @@ -42,6 +43,13 @@ type ProtocolLXD struct { project string } +// Disconnect gets rid of any background goroutines +func (r *ProtocolLXD) Disconnect() { + if r.chConnected != nil { + close(r.chConnected) + } +} + // GetConnectionInfo returns the basic connection information used to interact with the server func (r *ProtocolLXD) GetConnectionInfo() (*ConnectionInfo, error) { info := ConnectionInfo{} diff --git a/client/lxd_events.go b/client/lxd_events.go index 3c83132053..67ff94a436 100644 --- a/client/lxd_events.go +++ b/client/lxd_events.go @@ -52,6 +52,7 @@ func (r *ProtocolLXD) GetEvents() (*EventListener, error) { for { select { case <-time.After(time.Minute): + case <-r.chConnected: case <-stopCh: break } diff --git a/client/simplestreams.go b/client/simplestreams.go index 471cf54b4e..205661d6e1 100644 --- a/client/simplestreams.go +++ b/client/simplestreams.go @@ -17,6 +17,11 @@ type ProtocolSimpleStreams struct { httpCertificate string } +// Disconnect is a no-op for simplestreams +func (r *ProtocolSimpleStreams) Disconnect() { + return +} + // GetConnectionInfo returns the basic connection information used to interact with the server func (r *ProtocolSimpleStreams) GetConnectionInfo() (*ConnectionInfo, error) { info := ConnectionInfo{}
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel