項目中用的Express,用了express-myconnection中間件創(chuàng)建連接池,連接限制數(shù)量為10。在運行過程中發(fā)現(xiàn)若鏈接數(shù)量超過限制,就直接卡死,無論等待多久也無法進行新的查詢,也不報錯,再次獲取鏈接。出現(xiàn)這個問題的原因肯定是由于已創(chuàng)建的鏈接沒有進行釋放。然而這個看了中間件的源碼,也只是對mysql模塊進行的簡單封裝,調(diào)用的也是mysql.createPool。于是我想知道這個情況到底是我代碼的問題,還是mysql模塊自身的問題,各位大神賜教!運行代碼: exports.index = function(req, res) {
console.log('start');
req.getConnection(function(err,con){
console.log('got connection'); if(err){
res.end('err');
}
var sql='select id from integrated_db.community'
con.query(sql,[],function(err,data){
res.end('data');
});
});
}控制臺 多次刷新頁面,會持續(xù)輸出:> start > got connection > start > got connection> start got> connection> start> got connection控制臺 當刷新次數(shù)多了之后,就只會出現(xiàn):> start> got connection> start> start> start> start> start后面就一直卡死了,不會有新的鏈接能夠進行了。求指教。
使用mysql模塊創(chuàng)建連接池,出現(xiàn)鏈接不釋放,卡死的問題
胡子哥哥
2018-09-04 13:21:11