Skip to content

Commit

Permalink
fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ata-no-one committed Mar 14, 2024
1 parent 70e6e53 commit ff36a1a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions typescript/src/Vaas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,9 @@ export class Vaas {
return new Promise((resolve, reject) => {
const guid = uuidv4();
if (this.debug) console.debug("uuid", guid);
let contentLength = 0;
this.verdictPromises.set(guid, {
resolve: async (verdictResponse: VerdictResponse) => {
var contentLength;
if (verdictResponse.verdict === Verdict.UNKNOWN) {
contentLength = stream.readableLength;
await this.upload(verdictResponse, stream, contentLength);
this.verdictPromises.delete(guid);
}
if (
verdictResponse.verdict !== Verdict.UNKNOWN &&
contentLength === 0
Expand All @@ -256,6 +251,13 @@ export class Vaas {
"Server returned verdict without receiving content",
);
}
if (verdictResponse.verdict === Verdict.UNKNOWN) {
contentLength = stream.readableLength;
await this.upload(verdictResponse, stream, contentLength);
return;
}
this.verdictPromises.delete(guid);

resolve(
new VaasVerdict(verdictResponse.sha256, verdictResponse.verdict, verdictResponse.detections, verdictResponse.lib_magic),
);
Expand Down

0 comments on commit ff36a1a

Please sign in to comment.