0

I'm sending a post request to the same url multiple times in a row. Some of the requests return 200 status code and some return 204 saying no content. the request updates some content in a mongo database. I don't know if this is relevant. What could cause this problem?

My index.js:

app.post('/updatetrialsession',authenticateJWT ,(req,res)=>{
    
    User.findOne({username:req.user.username}).then(user=>{
        var trialIdx=user.examTrials.findIndex(it=>it.trialId===req.body.trialId)
        var questionIdx=req.body.questionIdx
        if(trialIdx!==-1){
            user.examTrials[trialIdx].questions[questionIdx]=req.body.question
            user.examTrials[trialIdx].currentQuestion=questionIdx+1
            user.examTrials[trialIdx].countDown=req.body.countDown
            user.examTrials[trialIdx].numOfSolved=req.body.numOfSolved 
            var filter={
                'username':user.username
            }
            var update={
                $set:{
                    'examTrials':user.examTrials
                }
            }
            User.findOneAndUpdate(filter,update).then(user=>{
                console.log('updated')
                res.json({
                    status:"success"
                })
            })   
        }  
    })
})

Note: all requests go to this url "/epdatetrialsession". when there's a 20 sec gap between each request everything works just fine. but when the server get flooded with say a request every 2 seconds or so, some return with 204 status code

  • Can you share the code of your express app relevant to this question? It could be a number of things... – Dominik Jul 02 '20 at 02:30

1 Answers1

0

I have had the same issue once. In my experience, When sending multiple number of requests to the server within a very short period of time, sometimes the server fails to answer all of them. Depends on the server capability. Did you try to check this by, sending the request for only the ones which returns 204 one at a time and see whether they still returns a 204? If so, the server has responded correctly even when sending the requests in a row. But if the server return a content with 200 when sending one at a time, then the issue might be with the server when handling multiple requests at a time.

  • All the requests I'm talking about are to the same route with fairly similar headers and body to each other. So I believe it's independent of the "route" or "request body". I believe it's related to the server capability. I'm on localhost will this be solved after deployment at least? – Mohammed Magdy Jul 02 '20 at 10:58