From c6dda05fa4ee98f4f975d09495c9635c6bacfb7b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 15 Nov 2024 19:54:01 -0800 Subject: [PATCH] server: force ipv4 on cluster connect --- server/src/scrypted-cluster-main.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/src/scrypted-cluster-main.ts b/server/src/scrypted-cluster-main.ts index 79f4e8542..08e77a84c 100644 --- a/server/src/scrypted-cluster-main.ts +++ b/server/src/scrypted-cluster-main.ts @@ -1,5 +1,6 @@ import type { ForkOptions } from '@scrypted/types'; import { once } from 'events'; +import net from 'net'; import { install as installSourceMapSupport } from 'source-map-support'; import type { Readable } from 'stream'; import tls from 'tls'; @@ -109,9 +110,22 @@ export function startClusterClient(mainFilename: string) { // to hang the app since no window is created yet. await sleep(1000); - const socket = tls.connect({ + const rawSocket = net.connect({ host, port, + // require ipv4 to normalize cluster address. + family: 4, + }); + + try { + await once(rawSocket, 'connect'); + } + catch( e) { + continue; + } + + const socket = tls.connect({ + socket: rawSocket, rejectUnauthorized: false, });