Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added temporary workaround to fix corrupted zip file #6965

Merged
merged 2 commits into from
Oct 9, 2023
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
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