fix: the page waits for the antivirus while the server can still be on the file (DTF-WEB-2E)
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 8m39s
Build and deploy / Secret scan and release gate (push) Successful in 4s
Build and deploy / Publish images (push) Has been skipped
Some checks failed
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Failing after 8m39s
Build and deploy / Secret scan and release gate (push) Successful in 4s
Build and deploy / Publish images (push) Has been skipped
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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;attempt<attempts;attempt++){
|
||||
// The antivirus streams the whole file (about a second per 2 MB) and takes
|
||||
// one file at a time for every customer, so a file can wait behind others
|
||||
// first: two files at once, the second gave up at two and a half minutes
|
||||
// (Sentry DTF-WEB-2E). The page waits while the server can still be on it:
|
||||
// its own time plus the 15 minutes the worker gives one file before it
|
||||
// calls the scan stuck (app/scanning.py SCAN_STUCK_SECONDS). Each second
|
||||
// for the first two and a half minutes, then every five.
|
||||
const limit=(900+Math.ceil(file.size/2e6))*1000;
|
||||
for(let waited=0;waited<limit;){
|
||||
if(signal?.aborted)throw cancelled();
|
||||
const checked=await api(prefix+'/'+id);
|
||||
if(checked.scan_state==='clean')return id;
|
||||
if(['rejected','error'].includes(checked.scan_state))throw new Error(checked.scan_reason||'Arquivo bloqueado pela verificação de segurança.');
|
||||
progress('Verificando segurança de '+file.name+'…');
|
||||
await new Promise(resolve=>setTimeout(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.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user