I think I just discovered something really weird with either node.js or the browsers. So node.js should be non-blocking but a simple setTimeout blocks the whole website for the same client.
This is the server code:
// Create HTTP Server
var http = require('http');
// Create page number holder
var page = 0;
http.createServer(function (req, res) {
// Increment Page Number
page++;
// Log page load
console.log('LOAD PAGE', page);
// Set response header
res.writeHead(200, {'Content-Type': 'text/plain'});
// Wait 10 seconds and write Hello World message to client.
setTimeout(function(){ res.end('Hello World\n'); }, 10000);
}).listen(5000); // Listen on port 5000
// Log server start
console.log('Server running on port 5000.');
So what I'm talking about is when I try to open http://mysite.com:5000/ in Chrome(Version 25.0.1364.152) with two tabs, the first tab has to finish before the second tab is being processed by node.js.
It looks like this:
Client: Open Tab1
> server console: LOAD PAGE 1
Client: Open Tab2
> server console: Nothing happens
Server: Wait 10 seconds
> server console: LOAD PAGE 2
I would expect node.js to run both requests right away otherwise this is not non-blocking. I already tested this with Firefox 19, so it seems browsers behave the same way regarding this.
So what's happening? Am I missing something?? :OOOO
UPDATE
I just run the tests in Safari(6.0.2) and it works normally, so this might be a browser issue with Chrome and Firefox and maybe others.
Tested with Node.js Version v0.6.17 and v0.8.21
{'Content-Type': 'text/plain','Connection':'close'}as headers?