fix(app): avoid duplicate bootstrap connection client

This commit is contained in:
Mohamed Boudra
2026-04-22 13:26:45 +07:00
parent 6b210df471
commit 2706d5e934
2 changed files with 16 additions and 29 deletions
+12 -11
View File
@@ -11,6 +11,7 @@ import {
connectionFromListen,
normalizeStoredHostProfile,
upsertHostConnectionInProfiles,
registryHasConnection,
type HostConnection,
type HostProfile,
} from "@/types/host-connection";
@@ -1265,20 +1266,20 @@ export class HostRuntimeStore {
private async bootstrapLocalhost(): Promise<void> {
try {
try {
const { client, serverId, hostname } = await connectToDaemon(
{
id: `bootstrap:${DEFAULT_LOCALHOST_ENDPOINT}`,
type: "directTcp",
endpoint: DEFAULT_LOCALHOST_ENDPOINT,
},
{ timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS },
);
const connection = connectionFromListen(DEFAULT_LOCALHOST_ENDPOINT);
if (!connection || registryHasConnection(this.hosts, connection)) {
return;
}
await this.upsertDirectConnection({
try {
const { client, serverId, hostname } = await connectToDaemon(connection, {
timeoutMs: DEFAULT_LOCALHOST_BOOTSTRAP_TIMEOUT_MS,
});
await this.upsertHostConnection({
serverId,
endpoint: DEFAULT_LOCALHOST_ENDPOINT,
label: hostname ?? undefined,
connection,
existingClient: client,
});
} catch {
+4 -18
View File
@@ -310,24 +310,10 @@ export function normalizeStoredHostProfile(entry: unknown): HostProfile | null {
};
}
export function normalizeEndpointOrNull(endpoint: string): string | null {
try {
return normalizeHostPort(endpoint);
} catch {
return null;
}
export function hostHasConnection(host: HostProfile, connection: HostConnection): boolean {
return host.connections.some((existing) => hostConnectionEquals(existing, connection));
}
export function hostHasDirectEndpoint(host: HostProfile, endpoint: string): boolean {
const normalized = normalizeEndpointOrNull(endpoint);
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));
export function registryHasConnection(hosts: HostProfile[], connection: HostConnection): boolean {
return hosts.some((host) => hostHasConnection(host, connection));
}