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:
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user