From cc460c6e0c2a9a2f6e9785653ebc34f88f77bea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 2 Dec 2026 14:56:25 -0300 Subject: [PATCH] fix: the page waits for the antivirus while the server can still be on the file (DTF-WEB-2E) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The worker scans one file at a time for every customer. On 2026-12-02 two files were checked together, and the one waiting behind the other gave up after two and a half minutes with "Verificação de segurança pendente"; its budget counted only its own scan, not the queue. The page now waits the file's own time plus the 15 minutes the worker gives one file before it calls the scan stuck (SCAN_STUCK_SECONDS), polling each second for the first two and a half minutes and then every five, and stops at once when the customer removes the file. A scan that never ends still says so. Co-Authored-By: Claude Opus 5.5 --- tests/upload_retry_test.mjs | 24 +++++++++++++++++++++++- web/upload.js | 18 +++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/tests/upload_retry_test.mjs b/tests/upload_retry_test.mjs index 7db393b..8eecb44 100644 --- a/tests/upload_retry_test.mjs +++ b/tests/upload_retry_test.mjs @@ -17,6 +17,7 @@ let calls; let delays; let fetches; let onTimeout; +let scanStates = []; globalThis.setTimeout = (fn, delay) => { delays.push(delay); @@ -58,7 +59,7 @@ const makeApi = completeSteps => { if (step instanceof Error) throw step; return step ?? {}; } - if (path === '/uploads/u1') return {scan_state: 'clean'}; + if (path === '/uploads/u1') return {scan_state: scanStates.length ? scanStates.shift() : 'clean'}; throw new Error('caminho inesperado: ' + path); }; }; @@ -198,4 +199,25 @@ const run = async (completeSteps, {abortAfter} = {}) => { } } +// The antivirus takes one file at a time for every customer: a file waiting +// behind others is still waited for, past the old two and a half minutes +// (Sentry DTF-WEB-2E), polling every 5 s after the first 150. +{ + scanStates = Array(250).fill('pending'); + const {result, error} = await run([{}]); + assert.equal(error, undefined); + assert.equal(result, 'u1'); + const waits = delays.filter(d => d === 1000 || d === 5000); + assert.ok(waits.filter(d => d === 1000).length === 150 && waits.includes(5000)); +} +// A scan the server never finishes ends with the message, after its 15 minutes. +{ + scanStates = Array(5000).fill('pending'); + const {error} = await run([{}]); + assert.match(error?.message || '', /Verificação de segurança pendente/); + const waited = delays.filter(d => d === 1000 || d === 5000).reduce((t, d) => t + d, 0); + assert.ok(waited >= 900000 && waited < 910000, 'waited ' + waited); + scanStates = []; +} + console.log('upload retry checks passed'); diff --git a/web/upload.js b/web/upload.js index 6ea27f8..d34124a 100644 --- a/web/upload.js +++ b/web/upload.js @@ -69,15 +69,23 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr if(!id){state=await withRetry(options=>api(startPath,{name:file.name,size:file.size},options));id=state.id;if(resume)localStorage.setItem(key,id);} async function waitForScan(){ onBytes(file.size); - // The antivirus streams the whole file: about a second per 2 MB, and at - // least two and a half minutes. - const attempts=Math.max(150,Math.ceil(file.size/2e6)); - for(let attempt=0;attemptsetTimeout(resolve,1000)); + const pause=waited<150000?1000:5000; + await new Promise(resolve=>setTimeout(resolve,pause)); + waited+=pause; } throw new Error('Verificação de segurança pendente. Tente novamente para consultar o resultado.'); }