Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Added temporary workaround to fix corrupted zip file (cvat-ai#6965)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored and mikhail-treskin committed Oct 25, 2023
1 parent d8ff95a commit 4d602a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions cvat-core/src/download.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ onmessage = (e) => {
.then((response) => {
postMessage({
responseData: response.data,
headers: response.headers,
id: e.data.id,
isSuccess: true,
});
Expand Down
28 changes: 25 additions & 3 deletions cvat-core/src/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class WorkerWrappedAxios {
if (e.data.id in requests) {
try {
if (e.data.isSuccess) {
requests[e.data.id].resolve(e.data.responseData);
requests[e.data.id].resolve({ data: e.data.responseData, headers: e.data.headers });
} else {
requests[e.data.id].reject(new AxiosError(e.data.message, e.data.code));
}
Expand Down Expand Up @@ -1495,7 +1495,7 @@ async function getImageContext(jid: number, frame: number): Promise<ArrayBuffer>
}
}

async function getData(jid: number, chunk: number, quality: ChunkQuality): Promise<ArrayBuffer> {
async function getData(jid: number, chunk: number, quality: ChunkQuality, retry = 0): Promise<ArrayBuffer> {
const { backendAPI } = config;

try {
Expand All @@ -1509,7 +1509,29 @@ async function getData(jid: number, chunk: number, quality: ChunkQuality): Promi
responseType: 'arraybuffer',
});

return response;
const contentLength = +(response.headers || {})['content-length'];
if (Number.isInteger(contentLength) && response.data.byteLength < +contentLength) {
if (retry < 10) {
// corrupted zip tmp workaround
// if content length more than received byteLength, request the chunk again
// and log this error
setTimeout(() => {
throw new Error(
`Truncated chunk, try: ${retry}. Job: ${jid}, chunk: ${chunk}, quality: ${quality}. ` +
`Body size: ${response.data.byteLength}`,
);
});
return await getData(jid, chunk, quality, retry + 1);
}

// not to try anymore, throw explicit error
throw new Error(
`Truncated chunk. Job: ${jid}, chunk: ${chunk}, quality: ${quality}. ` +
`Body size: ${response.data.byteLength}`,
);
}

return response.data;
} catch (errorData) {
throw generateError(errorData);
}
Expand Down

0 comments on commit 4d602a7

Please sign in to comment.