Skip to content

Commit c3a0b4e

Browse files
committed
fix(cli): use size-adaptive timeouts for publish uploads
The flat 30s timeout caused large project uploads to abort before the S3 PUT could complete. Compute timeout from archive size at ~500 KB/s with a 120s floor, so a 78 MB project gets ~164s and a 500 MB project gets ~17 min. Metadata requests keep the original 30s timeout.
1 parent 26b8e2a commit c3a0b4e

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎packages/cli/src/utils/publishProject.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import AdmZip from "adm-zip";
55
const IGNORED_DIRS = new Set([".git", "node_modules", "dist", ".next", "coverage"]);
66
const IGNORED_FILES = new Set([".DS_Store", "Thumbs.db"]);
77
const PUBLISH_CONTENT_TYPE = "application/zip";
8-
const PUBLISH_REQUEST_TIMEOUT_MS = 30_000;
8+
const PUBLISH_METADATA_TIMEOUT_MS = 30_000;
9+
const PUBLISH_UPLOAD_MIN_TIMEOUT_MS = 120_000;
10+
const PUBLISH_UPLOAD_BYTES_PER_SECOND = 500_000;
911

1012
export interface PublishArchiveResult {
1113
buffer: Buffer;
@@ -142,6 +144,13 @@ async function readErrorMessage(response: Response, fallback: string): Promise<s
142144
return text.trim() ? `${fallback}: ${text.trim().slice(0, 180)}` : fallback;
143145
}
144146

147+
function uploadTimeoutMs(byteLength: number): number {
148+
return Math.max(
149+
PUBLISH_UPLOAD_MIN_TIMEOUT_MS,
150+
Math.ceil((byteLength / PUBLISH_UPLOAD_BYTES_PER_SECOND) * 1000),
151+
);
152+
}
153+
145154
function shouldIgnoreSegment(segment: string): boolean {
146155
return segment.startsWith(".") || IGNORED_DIRS.has(segment) || IGNORED_FILES.has(segment);
147156
}
@@ -214,7 +223,7 @@ async function publishProjectArchiveDirect(
214223
method: "POST",
215224
body,
216225
headers,
217-
signal: AbortSignal.timeout(PUBLISH_REQUEST_TIMEOUT_MS),
226+
signal: AbortSignal.timeout(uploadTimeoutMs(archive.buffer.byteLength)),
218227
});
219228

220229
const payload = await readJson(response);
@@ -243,7 +252,7 @@ async function publishProjectArchiveStaged(
243252
"content-type": "application/json",
244253
heygen_route: "canary",
245254
},
246-
signal: AbortSignal.timeout(PUBLISH_REQUEST_TIMEOUT_MS),
255+
signal: AbortSignal.timeout(PUBLISH_METADATA_TIMEOUT_MS),
247256
});
248257

249258
if (uploadResponse.status === 404 || uploadResponse.status === 405) {
@@ -260,7 +269,7 @@ async function publishProjectArchiveStaged(
260269
method: "PUT",
261270
body: new Blob([archiveArrayBuffer(archive)], { type: stagedUpload.contentType }),
262271
headers: stagedUpload.uploadHeaders,
263-
signal: AbortSignal.timeout(PUBLISH_REQUEST_TIMEOUT_MS),
272+
signal: AbortSignal.timeout(uploadTimeoutMs(archive.buffer.byteLength)),
264273
});
265274
if (!s3Response.ok) {
266275
throw new Error(await readErrorMessage(s3Response, "Failed to upload project archive"));
@@ -277,7 +286,7 @@ async function publishProjectArchiveStaged(
277286
"content-type": "application/json",
278287
heygen_route: "canary",
279288
},
280-
signal: AbortSignal.timeout(PUBLISH_REQUEST_TIMEOUT_MS),
289+
signal: AbortSignal.timeout(uploadTimeoutMs(archive.buffer.byteLength)),
281290
});
282291

283292
const completePayload = await readJson(completeResponse);

0 commit comments

Comments
 (0)