Cannot handle multiple requests on same http path #4745
-
Versionv16.19.1 PlatformDarwin laurenzos-macbook-pro.home 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64 SubsystemNo response What steps will reproduce the bug?Copy and paste the following code in the index.js file const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
const p = new Promise((resolve) => {
setTimeout(() => {
resolve()
}, 10000)
})
p.then(() => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end("hello " + req.url);
})
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
}); and start the server. First case: Second case: How often does it reproduce? Is there a required condition?Always reproducible. What is the expected behavior? Why is that the expected behavior?I would expect the second case to work like the first case: What do you see instead?In the second case, the second tab is loading for 10 seconds, as if the second request was beginning to be handled only after the first one is finished, while in the first case, they seem to be handled at the same time. Additional informationI know Node.js is single-threaded, however it does not explain the difference between the two cases. |
Beta Was this translation helpful? Give feedback.
Replies: 0 comments 2 replies
-
I can't reproduce this. Could you please use |
Beta Was this translation helpful? Give feedback.
-
Converted to a discussion because there's no bug. Your question really is "why does my browser work this way?" and the answer is "because it's configured to work like that." Like Tobias said, use curl instead. |
Beta Was this translation helpful? Give feedback.
Converted to a discussion because there's no bug. Your question really is "why does my browser work this way?" and the answer is "because it's configured to work like that."
Like Tobias said, use curl instead.