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"); 
Hello everybody. I am stuck in this code. Whenever I call the same request 11 times, nodejs stops responding and does not even register "New request:" + request.url. Does anyone have an idea of ​​what is going on?

Many thanks.

+6
source share
2 answers

Sorry to be late back. I understood what the problem is, but I don’t quite understand. In the connection loop, I used functions that actually only simulated values ​​(usually captured by the request). That was the problem. If you do not issue a database query in pg.connect and loop on it, it seems that the connections are not closing properly. Thus, the pool of connections seems to break. I hope I was clear enough.

Thanks anyway for your help.

+2
source

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

0
source

Source: https://habr.com/ru/post/899637/


All Articles