6

The Problem: If I comment out the express['static'] line, the code runs perfectly. If I include it (or change the order), the app hangs for a while before responding.

To Recreate: Run the app, load up a browser and go to 127.0.0.1:51783 Refresh the page constantly (or use curl), the console will give you an output similar to:

GET / 1 ms

Then, when the timeout kicks in and the 15 requests are sent, the server becomes unresponsive and you get the following:

Server Now Unresponsive but requests queued
GET / 35549 ms

app.js

var http = require('http');
var express = require('express');
var app = express.createServer();
app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
app.use(express.bodyParser());
app.use(express['static'](__dirname + '/')); //Comment me and all works perfectly!
app.listen(51783);
http.globalAgent.maxSockets = 500; //doesn't help
setTimeout(function(){
  console.log('Server Now Unresponsive but requests queued');
  [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].forEach(function(item){
    http.request({host:'http://cnn.com', port:80, path:'/null', method:'GET'}, function(res){
    }).on('error', function(e){});
  });

},5000);
chillbo
  • 61
  • 3
  • I'm having the exact same problem. I assumed it was coming from a different piece of middleware but have now isolated it to connect.static. You have any luck solving this in the end Chillbo? – Sam Sharp May 02 '13 at 15:59
  • We are having this issue as well. – Ryan Walls Feb 27 '14 at 19:46

1 Answers1

-2

There is something not quite right about that http request. I recommend using the request module for this sort of thing. Either way this works:

var http = require('http');
var express = require('express');
var app = express.createServer();

app.configure(function(){
  app.use(express.logger({ format: '\x1b[1m:method\x1b[0m \x1b[33m:url\x1b[0m :response-time ms' }));
  app.use(express.bodyParser());
  app.use(express['static'](__dirname + '/public')); //Comment me and all works perfectly!
})

app.listen(51783);
var request = require('request');


setTimeout(function(){
  console.log('Server Now Unresponsive but requests queued');
  [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15].forEach(function(item){
    request('http://www.google.com', function (error, response, body) {
        console.log("request number "+item+" received")
    })
  });
},5000);
henry.oswald
  • 5,304
  • 13
  • 51
  • 73
  • This answer doesn't respond to the problem. – Sam Sharp May 02 '13 at 15:58
  • 1
    It kinda does. I got here because I was having a problem with express.static, http-proxy and http.request. Switching from http.request to the request library resolved the problem. – sheldonh May 23 '13 at 12:09