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
- 我已经安装了“npm install express”命令。 但仍然收到错误
- 如何将聊天与nodejs和xmpp集成到我现有的Web应用程序中?
- 如何在Docker中执行非全局的npm二进制文件
- 直接调用全局安装的Node.js模块
- 在Passport策略callback中获取请求对象
- 在自定义静态创build中包装Model.create
- Express 4中间件error handling程序不被调用
- require('file.json')vs readFile('/ file.json',callback)vs readFileSync('/ file.json','utf-8')
- 处理Express中间件中的参数