1
0
mirror of https://github.com/lxc/incus.git synced 2026-02-05 09:46:19 +01:00

client: Replace chConnected with ctxConnected

Fixes a crash when Disconnect() is called multiple times.

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
This commit is contained in:
Thomas Parrott
2022-02-15 17:23:51 +00:00
parent cf12b5c3c5
commit 2a9532ef7a
4 changed files with 44 additions and 30 deletions

View File

@@ -104,15 +104,18 @@ func ConnectLXDHTTPWithContext(ctx context.Context, args *ConnectionArgs, client
args = &ConnectionArgs{}
}
ctxConnected, ctxConnectedCancel := context.WithCancel(context.Background())
// Initialize the client struct
server := ProtocolLXD{
ctx: ctx,
httpHost: "https://custom.socket",
httpProtocol: "custom",
httpUserAgent: args.UserAgent,
chConnected: make(chan struct{}, 1),
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
ctx: ctx,
httpHost: "https://custom.socket",
httpProtocol: "custom",
httpUserAgent: args.UserAgent,
ctxConnected: ctxConnected,
ctxConnectedCancel: ctxConnectedCancel,
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
}
// Setup the HTTP client
@@ -154,16 +157,19 @@ func ConnectLXDUnixWithContext(ctx context.Context, path string, args *Connectio
args = &ConnectionArgs{}
}
ctxConnected, ctxConnectedCancel := context.WithCancel(context.Background())
// Initialize the client struct
server := ProtocolLXD{
ctx: ctx,
httpHost: "http://unix.socket",
httpUnixPath: path,
httpProtocol: "unix",
httpUserAgent: args.UserAgent,
chConnected: make(chan struct{}, 1),
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
ctx: ctx,
httpHost: "http://unix.socket",
httpUnixPath: path,
httpProtocol: "unix",
httpUserAgent: args.UserAgent,
ctxConnected: ctxConnected,
ctxConnectedCancel: ctxConnectedCancel,
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
}
// Determine the socket path
@@ -287,17 +293,20 @@ func httpsLXD(ctx context.Context, url string, args *ConnectionArgs) (InstanceSe
args = &ConnectionArgs{}
}
ctxConnected, ctxConnectedCancel := context.WithCancel(context.Background())
// Initialize the client struct
server := ProtocolLXD{
ctx: ctx,
httpCertificate: args.TLSServerCert,
httpHost: url,
httpProtocol: "https",
httpUserAgent: args.UserAgent,
bakeryInteractor: args.AuthInteractor,
chConnected: make(chan struct{}, 1),
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
ctx: ctx,
httpCertificate: args.TLSServerCert,
httpHost: url,
httpProtocol: "https",
httpUserAgent: args.UserAgent,
bakeryInteractor: args.AuthInteractor,
ctxConnected: ctxConnected,
ctxConnectedCancel: ctxConnectedCancel,
eventConns: make(map[string]*websocket.Conn),
eventListeners: make(map[string][]*EventListener),
}
if args.AuthType == "candid" {