Why node exits without any error messages?
Opened this issue · 3 comments
Hello!
I trying to use your great nodejs module in system monitoring daemon and see very strange behavior. Please see working code sample. When I run it without changes node will exits at 1050-1100 step without any error messages. But this sample have infinite loop.
Changes of timeouts in line 10 are not helps. If I uncomment line 25 with console.log of result object - all begins works ok. If I not touch line 25 and comment line 31 - all works ok too.
What is the reason for this strange behavior?
var win32ole = require( 'win32ole' );
var x=0;
var locator = win32ole.client.Dispatch('WbemScripting.SWbemLocator');
var svr = locator.ConnectServer('.', 'root/cimv2'); // . = self PC
function test() {
wmi_query( [ 'DeviceID', 'FreeSpace', 'Size' ], 'Win32_LogicalDisk', 'Size != Null' );
x++; console.log( x );
setTimeout( test, 1 ); // tested values 1, 10, 50, 100 - all buggy
}
test();
function wmi_query( fields, from, where ) {
var q = 'SELECT ' + fields.join( ',' ) + ' FROM ' + from; if( where !== undefined ) q += ' WHERE ' + where;
q = svr.ExecQuery( q );
var count = q.Count;
var result = [];
for( var iq = 0; iq < count; iq++ ){
var item = q.ItemIndex( iq ), obj = {};
for( var i = 0; i < fields.length; i++ ) {
obj[ fields[ i ] ] = wmi_prop( item, fields[ i ] );
}
result.push( obj );
//console.log(obj); // 1050-1100 times w/o this
}
return( result );
}
function wmi_prop( obj, propertyname ){
var property = obj[propertyname]; // if remove this, works normally
return property == null ? 'NULL' : property;
};
Also I have a problem for select some fields from WQL. For example, I unable to get CurrentTimeZone value from Win32_OperatingSystem. Node exits with error:
OLE error: [CurrentTimeZone] -2147352570 [CurrentTimeZone] IDispatch::GetIDsOfNames AutoWrap() failed
Similar situation is with SettingID value from Win32_StartupCommand. Both of these values perfectly gets with using cscript.exe + JSscript.
Additional remark. Same code with console.log enabled in line 25 also causes error in 39880 iteration:
OLE error: [Count] -2147352567 [Count] = [1] (It always seems to be appeared at that time you mistake calling 'obj.get { ocv->getProp() }' <-> 'obj.call { ocv->invoke() }'.) IDispatch::Invoke AutoWrap() failed
In continuation of the dialog with myself :)
The above script also consumes a lot of memory. And memory usage raises every second. And your garbage collection functions don't change the picture.