Skip to content

Commit 96a2f0a

Browse files
fix(shared): relay client install survives antivirus-slowed first launch (pingdotgg#27426)
1 parent 905311d commit 96a2f0a

2 files changed

Lines changed: 59 additions & 12 deletions

File tree

‎packages/shared/src/relayClient.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,47 @@ describe("RelayClient", () => {
471471
),
472472
);
473473

474+
it.effect.skipIf(windowsHost)(
475+
"installs when the downloaded binary's first launch is held by an antivirus scan",
476+
() =>
477+
Effect.gen(function* () {
478+
const fileSystem = yield* FileSystem.FileSystem;
479+
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
480+
prefix: "t3-cloudflared-test-",
481+
});
482+
const scanning = yield* Deferred.make<void>();
483+
const manager = yield* RelayClient.makeCloudflaredRelayClient({
484+
baseDir,
485+
releaseAsset: testReleaseAsset,
486+
}).pipe(
487+
Effect.provideService(
488+
ChildProcessSpawner.ChildProcessSpawner,
489+
ChildProcessSpawner.make(() =>
490+
Deferred.succeed(scanning, undefined).pipe(
491+
Effect.andThen(Effect.sleep("25 seconds")),
492+
Effect.as(
493+
makeHandle(
494+
0,
495+
`cloudflared version ${RelayClient.CLOUDFLARED_VERSION} (built 2026-01-01-00:00 UTC)\n`,
496+
),
497+
),
498+
),
499+
),
500+
),
501+
);
502+
503+
const installing = yield* manager.install.pipe(Effect.forkChild);
504+
yield* Deferred.await(scanning);
505+
yield* TestClock.adjust("25 seconds");
506+
507+
expect(yield* Fiber.join(installing)).toMatchObject({
508+
status: "available",
509+
source: "managed",
510+
version: RelayClient.CLOUDFLARED_VERSION,
511+
});
512+
}).pipe(Effect.scoped, Effect.provide(layerInstallRuntime("linux"))),
513+
);
514+
474515
it.effect("rejects downloads whose checksum does not match the pinned manifest", () =>
475516
Effect.gen(function* () {
476517
const fileSystem = yield* FileSystem.FileSystem;

‎packages/shared/src/relayClient.ts‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ const INSTALL_LOCK_RETRY_DELAY = "100 millis";
141141
// Legacy locks have no owner; allow both ten-minute download stages and the install tail.
142142
const INSTALL_LOCK_LEGACY_STALE_MS = 30 * 60 * 1_000;
143143
const VERSION_PROBE_TIMEOUT = "10 seconds";
144+
// Antivirus scans can hold the first launch of a freshly downloaded binary for 20-30 s.
145+
const INSTALL_VALIDATION_TIMEOUT = "2 minutes";
144146

145147
const ACTIVATE_RETRY_COUNT = 40;
146148
const ACTIVATE_RETRY_DELAY = "250 millis";
@@ -299,19 +301,23 @@ export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function
299301
return platform === "win32" || (info.value.mode & 0o111) !== 0;
300302
});
301303

304+
const runVersionProbe = Effect.fn("cloudflared.runVersionProbe")(function* (
305+
executablePath: string,
306+
timeout: Duration.Input,
307+
) {
308+
return yield* spawner
309+
.string(ChildProcess.make(executablePath, ["version"], { stdin: "ignore", stderr: "ignore" }))
310+
.pipe(
311+
Effect.map(parseCloudflaredVersionOutput),
312+
Effect.timeoutOption(timeout),
313+
Effect.map(Option.getOrNull),
314+
Effect.orElseSucceed(() => null),
315+
);
316+
});
317+
302318
// Cache successful version probes per file revision; do not let transient failures hide valid binaries.
303319
const versionCache = yield* Cache.makeWith(
304-
(key: VersionProbeKey) =>
305-
spawner
306-
.string(
307-
ChildProcess.make(key.executablePath, ["version"], { stdin: "ignore", stderr: "ignore" }),
308-
)
309-
.pipe(
310-
Effect.map(parseCloudflaredVersionOutput),
311-
Effect.timeoutOption(VERSION_PROBE_TIMEOUT),
312-
Effect.map(Option.getOrNull),
313-
Effect.orElseSucceed(() => null),
314-
),
320+
(key: VersionProbeKey) => runVersionProbe(key.executablePath, VERSION_PROBE_TIMEOUT),
315321
{
316322
capacity: 16,
317323
timeToLive: (exit) =>
@@ -648,7 +654,7 @@ export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function
648654
}
649655
yield* report("validating");
650656
// Verify the pin so mislabeled assets cannot cause repeated redownloads.
651-
const installedVersion = yield* probeVersion(executablePath);
657+
const installedVersion = yield* runVersionProbe(executablePath, INSTALL_VALIDATION_TIMEOUT);
652658
if (installedVersion !== CLOUDFLARED_VERSION) {
653659
return yield* new RelayClientInstallError({
654660
reason: "validation_failed",

0 commit comments

Comments
 (0)