Currently because the Provider object (the return value of createDTraceProvider) is not referenced (in Javascript land) by Probe objects (returned from .addProbe()), it is possible for the Provider to be GC'd while Probes are still referred to and valid.
For example:
var mod_dtrace = require('dtrace-provider');
var prov = mod_dtrace.createDTraceProvider('testusdt');
var p1 = prov.addProbe('foo', 'int');
prov.enable();
var n = 0;
setInterval(function () {
p1.fire(function () { return ([n++]); });
}, 1000);
setTimeout(function () { process.exit(0); }, 30000);
Because the closure inside setInterval only holds a reference to p1 and not prov (since it didn't use prov), V8 will sometimes garbage-collect prov. At this point the finalizer for the provider runs and disables all the probes.
This means that sometimes when you run the code above, the dtrace probes will silently fail to fire without any error being produced.
I think that the Probe objects should store a reference to their Provider in their Javascript objects (as an internal-use property). This way the entire bundle of Provider + Probe objects has to be unreferenced before GC will collect any of them and cause finalizers to be called.
Currently because the Provider object (the return value of
createDTraceProvider
) is not referenced (in Javascript land) by Probe objects (returned from.addProbe()
), it is possible for the Provider to be GC'd while Probes are still referred to and valid.For example:
Because the closure inside
setInterval
only holds a reference top1
and notprov
(since it didn't useprov
), V8 will sometimes garbage-collectprov
. At this point the finalizer for the provider runs and disables all the probes.This means that sometimes when you run the code above, the dtrace probes will silently fail to fire without any error being produced.
I think that the Probe objects should store a reference to their Provider in their Javascript objects (as an internal-use property). This way the entire bundle of Provider + Probe objects has to be unreferenced before GC will collect any of them and cause finalizers to be called.