Domanda

I want to solve the problem of blocking requests for the same URI. I am using Express for routing requests.

app.get('/task', function(req, res){
  console.log("geted");
  setTimeout(function(){
    res.json({"status":"ok"});
    res.end();
  },10000);    
});

If I make two sequential request this uri [localhost / task], then the second "geted" appears only after the execution of the first request. 10 seconds after the first request.

geted
GET /task 200 10016ms - 20b
geted
GET /task 200 10005ms - 20b

Requests for other URI is not locked (thanks to Express), though up to that time, not yet sent two identical request.

The question is why and how to avoid / fix this problem?

nodejs v10.26.0 express v3.4.8

È stato utile?

Soluzione

This is not a node problem, this is caused by your browser.

If you send two identical requests in one browser instance (say, two open tabs in the same browser), then your browser will not send the second request until the first one is finished.

Try opening up two different browsers, like one Chrome and one Firefox, and send the request once from each. I'm betting you will see it behave the way you expect.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top