I'm using Node to send telnet commands to local device every second. I'm using the telnet-client module.
Here is a small example:
var telnet = require('telnet-client');
var params = {
host: '10.0.1.14',
execTimeout: 200
};
function doWork(callback) {
var connection = new telnet();
connection.on('connect', function(prompt) {
console.log("New command");
connection.exec("CMD");
callback();
});
connection.on('timeout', function() {
connection.end();
});
connection.on('error', function(error) {
console.log('connection error: '+error);
connection.end();
});
connection.on('close', function() {
connection.destroy();
connection = null;
});
connection.connect(params);
}
function query_doWork() {
doWork(function() {
setTimeout(query_doWork, 1000);
});
}
query_doWork();
I've noticed, that when running this code it seems that the memory usage of the node process on my computer is just growing. What is the memory leak in this case? In the timeout event I'm calling end on the connection, and in the close event, the connection is destroyed.
What is the issue here?