简体   繁体   English

节点/快速挂起请求

[英]Node/Express pending request

I'm bit new on the Node.js front and for now its awesome. 我在Node.js前面有点新鲜,现在很棒。 I've encountered a small problem while running node (/w express) locally - Every request after the 10th one hangs and is marked as Pending in the Chrome Inspect Network. 我在本地运行节点(/ w express)时遇到了一个小问题 - 在第10个之后的每个请求都挂起并在Chrome Inspect Network中标记为Pending。

As for modules i'm using less-middleware, express, jade and MySQL and i only do one SQL query (using mysql.createPool). 至于模块我使用较少的中间件,快递,玉和MySQL,我只做一个SQL查询(使用mysql.createPool)。 Why is this request still Pending and how can i fix this? 为什么此请求仍处于待定状态,我该如何解决此问题?

Since i'm new at Node i'm not sure if i've tried everything so any help would be appreciated! 由于我是Node的新手,我不确定我是否已经尝试了所有内容,所以任何帮助都会受到赞赏!

It sounds like you're not releasing the MySQL connection you're getting back from the pool. 听起来你没有发布你从池中回来的MySQL连接。 If you don't, the pool will run out of free connections and will start waiting for any to become available (and until then, stall the request). 如果不这样做,则池将耗尽空闲连接并开始等待任何可用(并且在此之前停止请求)。

So your code should look similar to this: 所以你的代码看起来应该类似于:

var pool = mysql.createPool(...);
...
// in your request handler:
pool.getConnection(function(err, connection) {
  if (err) ...handle error...;
  connection.query(function(err, results) {
    // release connection
    connection.release();
    // handle results
    ...
    // send back a response
    res.send(...);
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM