Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ export const post = queryWithBody('POST');
export const put = queryWithBody('PUT');
export const doDelete = queryWithBody('DELETE');

// Upload deadline: generous for a slow link (1 s/MB on top of a 30 s base,
// never below 60 s) but bounded, so a stalled connection cannot hang a CI job
// forever. The bar keeps ticking while bytes flow; the deadline is absolute.
// Upload deadline: generous for a slow link (5 s/MB, i.e. ~200 KB/s, on top
// of a 30 s base, never below 60 s) but bounded, so a stalled connection cannot
// hang a CI job forever. The bar keeps ticking while bytes flow; the deadline
// is absolute.
Comment thread
sunnylqm marked this conversation as resolved.
const UPLOAD_TIMEOUT_BASE_MS = 30_000;
const UPLOAD_TIMEOUT_PER_MB_MS = 1_000;
const UPLOAD_TIMEOUT_PER_MB_MS = 5_000;
const UPLOAD_TIMEOUT_MIN_MS = 60_000;
const UPLOAD_MAX_RETRIES = 1;

Expand Down
10 changes: 10 additions & 0 deletions tests/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
replaceSession,
saveSession,
setApiToken,
uploadTimeoutMs,
} from '../src/api';
import * as runtime from '../src/utils/runtime';

Expand Down Expand Up @@ -289,4 +290,13 @@ describe('api.ts error helpers', () => {
}),
).toBe(true);
});
test('upload deadline allows 5 s per MB on a 30 s base, at least 60 s', () => {
const mb = 1048576;
expect(uploadTimeoutMs(0)).toBe(60_000);
expect(uploadTimeoutMs(5 * mb)).toBe(60_000);
expect(uploadTimeoutMs(10 * mb)).toBe(80_000);
expect(uploadTimeoutMs(100 * mb)).toBe(530_000);
// a partial megabyte counts as a whole one
expect(uploadTimeoutMs(100 * mb + 1)).toBe(535_000);
});
});