I am executing following code
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));
}
});
};
When callingFirstEvent function is called from waterfall model and if it stuck in error block of callingFirstEvent
if (err) {
logger.error('callingFirstEvent : Cannot fetch a client from pool', err);
next(null, limit);
return;
}
socket descriptors increased.
Here is how I am checking for total number of socket descriptors
ls -ltr /proc/cat /path of pid
/fd/ | grep socket | wc -l
How to close socket descriptors after they are opened? or is there any way not to open these sockets?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…