fix(shared): bound cloudflared download with 10-minute timeout (#14139)

Co-authored-by: Kevin Rajan <[email protected]>
This commit is contained in:
Kevin RajanandKevin Rajan authored and GitHub committed 2026-10-08 20:31:53 +00:00
1 parent af3d842a00
commit 580948708b
2 files changed
+57 -1

No files matched your search

+50 -1
View File
@@ -6,7 +6,6 @@ import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Hex from "effect/encoding/Hex";
import * as Fiber from "effect/Fiber";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as PlatformError from "effect/PlatformError";
@@ -57,6 +56,16 @@ const layerHttpClient = (bytes: Uint8Array) =>
),
);
// Records each request and never responds, simulating a wedged endpoint.
const layerStalledHttpClient = (requests: Array<unknown>) =>
Layer.succeed(
HttpClient.HttpClient,
HttpClient.make((request) => {
requests.push(request);
return Effect.never;
}),
);
// Answers `cloudflared version` with the version recorded for that path, which
// defaults to the pinned release; tests change it to simulate other binaries.
const layerSpawner = (commands: Array<string>, versions: Record<string, string> = {}) =>
@@ -767,4 +776,44 @@ describe("RelayClient", () => {
expect(renames.attempts).toBe(1);
}).pipe(Effect.scoped, Effect.provide(layerInstallRuntime(platform))),
);
it.effect("fails a stalled download after the download timeout", () => {
const requests: Array<unknown> = [];
return Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-cloudflared-test-",
});
const manager = yield* RelayClient.makeCloudflaredRelayClient({
baseDir,
releaseAsset: {
url: "https://example.test/cloudflared",
sha256: "00".repeat(32),
archive: "binary",
},
});
const child = yield* Effect.forkChild(manager.install);
// Spin until the wedged download is in flight, so the clock
// adjustment below cannot run before the timeout is armed.
while (requests.length === 0) {
yield* Effect.yieldNow;
}
// The download timeout is 10 minutes; advance past it.
yield* TestClock.adjust("11 minutes");
const error = yield* Fiber.join(child).pipe(Effect.flip);
expect(error).toBeInstanceOf(RelayClient.RelayClientInstallError);
expect(error.reason).toBe("download_failed");
}).pipe(
Effect.scoped,
Effect.provide(
Layer.mergeAll(
NodeServices.layer,
layerStalledHttpClient(requests),
layerSpawner([]),
layerHostRuntime({ PATH: "" }),
),
),
);
});
});
+7
View File
@@ -30,6 +30,11 @@ export const CLOUDFLARED_VERSION = "2026.10.0";
export const CLOUDFLARED_MIN_VERSION = "2025.6.1";
const CLOUDFLARED_PATH_ENV_NAME = "T3CODE_CLOUDFLARED_PATH";
// Generous bound for a ~40MB binary download; without it a stalled
// connection parks the install forever (same unbounded-wait family as the
// other relay/cloud network calls).
const CLOUDFLARED_DOWNLOAD_TIMEOUT = "10 minutes";
export type RelayClientExecutableSource = "override" | "managed" | "path";
export type RelayClientStatus =
@@ -441,6 +446,7 @@ export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function
) {
yield* report("downloading");
const response = yield* httpClient.execute(HttpClientRequest.get(asset.url)).pipe(
Effect.timeout(CLOUDFLARED_DOWNLOAD_TIMEOUT),
Effect.flatMap(HttpClientResponse.filterStatusOk),
Effect.mapError(
(cause) =>
@@ -453,6 +459,7 @@ export const makeCloudflaredRelayClient = Effect.fn("cloudflared.make")(function
);
const bytes = new Uint8Array(
yield* response.arrayBuffer.pipe(
Effect.timeout(CLOUDFLARED_DOWNLOAD_TIMEOUT),
Effect.mapError(
(cause) =>
new RelayClientInstallError({