Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
Node/Express API when getting mutlipel requests data gets mixed up and incorrect results occur

I have a nodejs/express backend api that when I get hundreds of requests within seconds I start to get mixed results where data is crossed between requests and leads to unexpected and incorrected results. Can someone point me to where I am incorrectly defining variables that when I get one of the await functions it causes the other variables to be overwritten with the next requests data and causing my issues.

router.post('/autoscan3', async(req,res,next) => {

  let authrule = "autoscan"

  console.log(req.body.companyDomain  + "   " + req.body.user + " for folder: " + req.body.folderid)


  let totalscans = 0;

  let client = await getDB();
  let authorizationResults = await checkAuthorization(client, req.body.companyDomain);

  const featureSet = authorizationResults.features;
  let company = authorizationResults.company;
  const clientid = authorizationResults.client_id;
  const clientsecret = authorizationResults.secret;

  let tenantid = await getTenantID(req.body.companyDomain, client);

  let token = await msgraphservices.getClientCredentialsAccessToken(tenantid, clientid, clientsecret)
  let scanResults = []
  let folderscans = 0;
  try{
    for(let a = 0; a < req.body.messages.length; a++){
      let senderAddress = req.body.messages[a].senderAddress;
      let emailBody = req.body.messages[a].emailBody;
      let messageid = req.body.messages[a].messageid;
      let receivedDateTime = req.body.messages[a].receivedDateTime;
      let user = req.body.messages[a].recieverAddress;
      let subject = req.body.messages[a].subject;
      let attachments = req.body.messages[a].attachments;
      let links = req.body.messages[a].emailBodyLinks;
      let headers = req.body.messages[a].headers
      let knownaddress
      if (senderAddress.includes(req.body.companyDomain)) {
        knownaddress = 10
      } else {
        knownaddress = await searchForSender(client, senderAddress, req.body.user, token, "");}

      let assessmentResults = await assessment(
            messageid,
            emailBody,
            senderAddress,
            user,
            subject,
            receivedDateTime,
            company,
            attachments,
            links,
            req.body.companyDomain,
            client,
            headers,
            knownaddress,
            featureSet,
            authrule
          )
      console.log('adding to folderscans')
      folderscans++
      try {
        await msgraphservices.updateUserCategory2(messageid, req.body.user, req.body.folderid, assessmentResults.riskFactor,token)
      }
      catch(e) {
        console.log(`error on category tag for ${messageid} with user ${req.body.user}`);
        console.log(e);
        }
    }
      console.log(`folder scans ${folderscans}`);
      totalscans = totalscans + folderscans
    return res.status(200).json({status:"success", totalscans:totalscans});
  }
  catch(e) {
    console.log(`error while trying to loop for user ${req.body.user}`)
    console.log(e)
    logapierror(e.stack, req.body.user, req.body)
    return res.status(200).json({status:'error', totalscans:totalscans, error:e});
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's very likely let client = await getDB();

If multiple requests use the same snapshot of the database but don't know about each other, it's very likely that they're overwriting each other's data.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda