NodeJS在11个请求后停止响应

Ele*_*dir 6 node.js

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");
Run Code Online (Sandbox Code Playgroud)

嗨,大家好.我坚持使用这段代码.每当我调用相同请求11次时,nodejs停止响应,甚至不记录"新请求:"+ request.url.任何人都知道发生了什么事?

非常感谢.

Ele*_*dir 2

抱歉回来晚了。我发现了问题所在,但并不完全理解。在连接循环中,我使用的函数实际上只是模拟值(通常由请求捕获)。这就是问题所在。如果您不在 pg.connect 中发出任何数据库请求并在其上循环,则连接似乎未正确关闭。所以连接池显然损坏了。希望我已经说得足够清楚了。

不管怎样,谢谢你的帮助。