Reputation: 203
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
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