fix(app): avoid duplicate bootstrap connection client
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
connectionFromListen,
|
connectionFromListen,
|
||||||
normalizeStoredHostProfile,
|
normalizeStoredHostProfile,
|
||||||
upsertHostConnectionInProfiles,
|
upsertHostConnectionInProfiles,
|
||||||
|
registryHasConnection,
|
||||||
type HostConnection,
|
type HostConnection,
|
||||||
type HostProfile,
|
type HostProfile,
|
||||||
} from "@/types/host-connection";
|
} from "@/types/host-connection";
|
||||||
@@ -1265,20 +1266,20 @@ export class HostRuntimeStore {
|
|||||||
|
|
||||||
private async bootstrapLocalhost(): Promise<void> {
|
private async bootstrapLocalhost(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
try {
|
const connection = connectionFromListen(DEFAULT_LOCALHOST_ENDPOINT);
|
||||||
const { client, serverId, hostname } = await connectToDaemon(
|
if (!connection || registryHasConnection(this.hosts, connection)) {
|
||||||
{
|
return;
|
||||||
id: `bootstrap:${DEFAULT_LOCALHOST_ENDPOINT}`,
|
}
|
||||||
type: "directTcp",
|
|
||||||
endpoint: DEFAULT_LOCALHOST_ENDPOINT,
|
|
||||||
},
|
|
||||||
{ timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS },
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.upsertDirectConnection({
|
try {
|
||||||
|
const { client, serverId, hostname } = await connectToDaemon(connection, {
|
||||||
|
timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.upsertHostConnection({
|
||||||
serverId,
|
serverId,
|
||||||
endpoint: DEFAULT_LOCALHOST_ENDPOINT,
|
|
||||||
label: hostname ?? undefined,
|
label: hostname ?? undefined,
|
||||||
|
connection,
|
||||||
existingClient: client,
|
existingClient: client,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -310,24 +310,10 @@ export function normalizeStoredHostProfile(entry: unknown): HostProfile | null {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeEndpointOrNull(endpoint: string): string | null {
|
export function hostHasConnection(host: HostProfile, connection: HostConnection): boolean {
|
||||||
try {
|
return host.connections.some((existing) => hostConnectionEquals(existing, connection));
|
||||||
return normalizeHostPort(endpoint);
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hostHasDirectEndpoint(host: HostProfile, endpoint: string): boolean {
|
export function registryHasConnection(hosts: HostProfile[], connection: HostConnection): boolean {
|
||||||
const normalized = normalizeEndpointOrNull(endpoint);
|
return hosts.some((host) => hostHasConnection(host, connection));
|
||||||
if (!normalized) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return host.connections.some(
|
|
||||||
(connection) => connection.type === "directTcp" && connection.endpoint === normalized,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function registryHasDirectEndpoint(hosts: HostProfile[], endpoint: string): boolean {
|
|
||||||
return hosts.some((host) => hostHasDirectEndpoint(host, endpoint));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user