Skip to content

Commit cb03d5b

Browse files
fix(tlon): add timeouts to file upload HTTP requests
1 parent f786efd commit cb03d5b

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎extensions/tlon/src/tlon-api.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ describe("uploadFile memex upload hardening", () => {
139139
expect(firstCall?.auditContext).toBe("tlon-memex-upload-url");
140140
expect(firstCall?.capture).toBe(false);
141141
expect(firstCall?.maxRedirects).toBe(0);
142+
expect(firstCall?.timeoutMs).toBe(30_000);
142143
const firstBodyRaw = firstCall?.init?.body;
143144
expect(typeof firstBodyRaw).toBe("string");
144145
const firstBody = JSON.parse(firstBodyRaw as string) as Record<string, unknown>;
@@ -156,6 +157,7 @@ describe("uploadFile memex upload hardening", () => {
156157
expect(secondCall?.auditContext).toBe("tlon-memex-upload");
157158
expect(secondCall?.capture).toBe(false);
158159
expect(secondCall?.maxRedirects).toBe(0);
160+
expect(secondCall?.timeoutMs).toBe(120_000);
159161
expect(secondCall?.init?.body).toBeInstanceOf(Blob);
160162
expect(mockRelease).toHaveBeenCalledTimes(2);
161163
});
@@ -504,6 +506,7 @@ describe("uploadFile custom S3 upload hardening", () => {
504506
expect(uploadCall?.auditContext).toBe("tlon-custom-s3-upload");
505507
expect(uploadCall?.capture).toBe(false);
506508
expect(uploadCall?.maxRedirects).toBe(0);
509+
expect(uploadCall?.timeoutMs).toBe(120_000);
507510
expect(uploadCall?.policy).toBeUndefined();
508511
expect(mockRelease).toHaveBeenCalledTimes(1);
509512
expect(vi.mocked(globalThis.fetch)).not.toHaveBeenCalled();

‎extensions/tlon/src/tlon-api.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ const MEMEX_BASE_URL = "https://memex.tlon.network";
4949
/** Max bytes to read from the Memex upload JSON response. */
5050
const MEMEX_UPLOAD_RESPONSE_MAX_BYTES = 64 * 1024;
5151

52+
/** Timeout for the Memex upload URL lookup request. */
53+
const TLON_MEMEX_UPLOAD_URL_TIMEOUT_MS = 30_000;
54+
55+
/** Timeout for the actual file upload to Memex or a custom S3 target. */
56+
const TLON_UPLOAD_TIMEOUT_MS = 120_000;
57+
5258
let currentClientConfig: ClientConfig | null = null;
5359

5460
export function configureClient(params: ClientConfig): void {
@@ -250,6 +256,7 @@ async function getMemexUploadUrl(params: {
250256
auditContext: "tlon-memex-upload-url",
251257
capture: false,
252258
maxRedirects: 0,
259+
timeoutMs: TLON_MEMEX_UPLOAD_URL_TIMEOUT_MS,
253260
});
254261
release = guarded.release;
255262
if (!guarded.response.ok) {
@@ -317,6 +324,7 @@ export async function uploadFile(params: UploadFileParams): Promise<UploadResult
317324
auditContext: "tlon-memex-upload",
318325
capture: false,
319326
maxRedirects: 0,
327+
timeoutMs: TLON_UPLOAD_TIMEOUT_MS,
320328
});
321329
release = guarded.release;
322330
assertTrustedMemexUploadUrl(guarded.finalUrl, "Memex final upload URL");
@@ -381,6 +389,7 @@ export async function uploadFile(params: UploadFileParams): Promise<UploadResult
381389
capture: false,
382390
maxRedirects: 0,
383391
policy: privateNetworkPolicy,
392+
timeoutMs: TLON_UPLOAD_TIMEOUT_MS,
384393
});
385394
release = guarded.release;
386395
if (!guarded.response.ok) {

0 commit comments

Comments
 (0)