NodeJS在11个请求后停止响应

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"); 

嗨,大家好。 我坚持这个代码。 每当我调用11次相同的请求,nodejs停止响应,甚至不会logging“新请求:”+ request.url。 任何人都知道发生了什么?

非常感谢。

对不起,迟到回来。 我发现了什么问题,但是没有完全理解。 在连接循环中,我使用的function实际上只是模拟值(通常由请求捕获)。 这是问题。 如果你不在pg.connect中发出任何数据库请求,并且在它上面循环,看起来连接不能正常closures。 所以连接池显然中断了。 希望我已经清楚了。

无论如何感谢您的帮助。

我认为这个问题是for循环中的asynchronous调用“pg.connect”。 尝试这个JS模块asynchronous