我正在执行以下代码
var pg = require('pg').native;
async.waterfall([
function (callback) {
//some code
},
function (result,callback) {
logger.debug('Async waterfall 2: Querying events.');
try {
callingFirstEvent(queryMode, request, foundEvents, callback);
} catch(ex) {
logger.error('callingFirstEvent::Error occurred in async waterfall 2: ' + ex.message);
}
},
function (result, callback) {
//some code
},
],
function (err, res) {
//some code
}
);
var callingFirstEvent = function (queryMode, request, foundEvents, callback) {
var conStringList = queryMode.conStringList;
var executeQuery = function (conString, limit, next) {
pg.connect(conString, function(err, client, done) {
//below error code is reason of increased socket descriptors
if (err) {
logger.error('callingFirstEvent : Cannot fetch a client from pool', err);
next(null, limit);
return;
}
client.query(sql, function (err, result) {
done();
if (err) {
logger.error('callingFirstEvent', err);
logger.error('sql:' + sql);
next(err, limit);
return;
}
//some code
}); // client.query
}); // pg.connect
}; // executeQuery
var schedule = [];
conStringList.forEach(function (conString, index) {
if (index == 0) {
schedule.push(async.apply(executeQuery, conString, request.query.max));
}
});
};
当呼叫firstevent函数从瀑布模型调用时,并且是否遇到了callfirstevent的错误块
if (err) {
logger.error('callingFirstEvent : Cannot fetch a client from pool', err);
next(null, limit);
return;
}
插座描述符增加。
这是我如何检查套接字描述符的总数
ls -ltr/proc/ cat /path of pid
/fd/|GREP插座|WC -L
打开后如何关闭插座描述符?还是有什么方法不打开这些插座?
您正在泄漏插座。大多数错误,实际上除了阅读超时以外的所有错误,对插座都是致命的,应该使您关闭插座。