fix(media): an uploader checks the relay's upload status before trusting it
A chunk of 0 looped forever, a huge chunk held the film in memory and a huge window opened a request (a thread on Kotlin) per piece. statusProblem checks chunk, window, received and landed; the client window is capped at 16. Same in MediaUploader, with tests on both sides. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -202,6 +202,26 @@ describe('pieces', () => {
|
||||
expect((await piece(4 * chunk)).status).toBe(404);
|
||||
});
|
||||
|
||||
test('a relay whose upload status is unusable is refused at once, not looped on', async () => {
|
||||
const bytes = new Uint8Array(DEFAULT_CHUNK_BYTES + 4096);
|
||||
const { result, bytes: sealed } = await sealMediaBytes(bytes);
|
||||
for (const bad of [
|
||||
{ chunk: 0, received: 0 },
|
||||
{ chunk: MAX_PIECE_BYTES * 4, received: 0 },
|
||||
{ chunk: DEFAULT_CHUNK_BYTES, received: -1 },
|
||||
{ chunk: DEFAULT_CHUNK_BYTES, received: 0, window: 0 },
|
||||
{ chunk: DEFAULT_CHUNK_BYTES, received: 0, landed: ['x'] },
|
||||
]) {
|
||||
let calls = 0;
|
||||
const relay = (async () => {
|
||||
calls++;
|
||||
return Response.json({ id: 'x', size: result.sealedSize, ...bad }, { status: 201 });
|
||||
}) as unknown as typeof fetch;
|
||||
await expect(new MediaClient('http://relay', OwnerKey.generate(), { fetch: relay }).putSealed(result, sealed)).rejects.toThrow(/unusable/);
|
||||
expect(calls).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
test('a single PUT holds one piece at most; bigger files are told to go up in pieces', async () => {
|
||||
const { app } = serve(new MemoryMediaStore());
|
||||
const owner = OwnerKey.generate();
|
||||
|
||||
Reference in New Issue
Block a user