Google Chrome queued request one by one when multiple requests to a localhost node application

Viewed 1192

Recently, I was testing the asynchronous behaviour of a nodejs express web application. My code was very simple

const express = require('express');
const app = express();

const port = 3000;

app.get('/', (req, res) => {
    console.log(`hello main start`);

    setTimeout(() => {
        const date = new Date();
        console.log(date);
        res.send(`hello work done at ${date}!`);
    }, 20000);

    console.log(`hello main end`);
});

app.listen(port, () => {
    console.log(`Example app listening on port ${port}`);
})

I found the experience that if I just open 2 tabs simultaneously to the endpoint url http://localhost:3000/ in my chrome browser without the developer tools opening, the request are fired one by one. How can I know they are are fired one by one is that when I observe the server console log, the second request only log start after when the request 1 finish. And hence I need 40 seconds to complete my 2 requests.

However I don't expect that above behaviour happens. So I try to do the same actions with postman.

But in this time, I found my postman will fire the 2 requests simultaneously and my server log the 2 request immediately as well.

What's more weird is that if I opens the 2 tab with chrome developer tool opening, the behaviour will be same as what I saw with the postman.

Can anyone have the explanation for this behaviour for the chrome? is it Google doing it on purpose on chrome?

1 Answers

Yes, this is Chrome's behavior. Identical requests to the same host will stall. This is apparent if you watch the network tab in the developer tools.

Stalled

Related