Elendir
Elendir

Reputation: 203

NodeJS stops responding after 11 requests

http.createServer(function(request, response) {
console.log("New request :"+request.url);
var found = false;
for(var i= 0; i < requests.length; i++){
    match = requests[i];
    if(match.method == request.method && request.url.match(match.regexp))
    {
        console.log("Matched request: "+match.url);
        pg.connect(databaseUrl, function(error, client) {
            if(error)
                processError(response, error);
            else
                match.action(client, request, response);
        });
        found = true;
        break;
    }
}
if(!found)
    processError(response, "Request url does not exist: "+request.url);
}).listen(3000);
sys.puts("Server running... waiting for requests");

Hi everyone. I'm stuck with this code. Whenever I call 11 times the same request, nodejs stops responding and does not even logs "New request: "+request.url. Anyone has an idea of what's going on ?

Thanks a lot.

Upvotes: 6

Views: 2224

Answers (2)

Elendir
Elendir

Reputation: 203

Sorry for the late come back. I found what was the problem but don't completely understand it. In the connect loop, I was using functions which were actually only simulating values (normally captured by a request). This was the problem. If you don't issue any database request in the pg.connect and loop on it, it seems the connections do not close properly. So the connection pool apparently breaks. Hope I've been clear enough.

Anyway thank you for your help.

Upvotes: 2

czizzy
czizzy

Reputation: 87

I think the problem is the async call "pg.connect" in a for loop. Try this js module async

Upvotes: 0

Related Questions