node-restify
node-restify copied to clipboard
cpuUsageThrottle plugin `close()` does not clean up properly
- [X] Used appropriate template for the issue type
- [X] Searched both open and closed issues for duplicates of this issue
- [X] Title adequately and concisely reflects the feature or the bug
Bug Report
When cleaning up resources on shutdown (or test teardown), calling close()
on the plugin does not properly clean up all resources.
Restify Version
8.3.2
Node.js Version
All
Expected behaviour
Calling plugin.close()
should allow process to exit.
Actual behaviour
close()
does not clean up handles, leaving process running.
Repro case
const cpuUsageThrottle = require('restify').plugins.cpuUsageThrottle;
const plugin = cpuUsageThrottle({
limit: 0.75,
max: 1,
interval: 50,
halfLife: 200
});
plugin.close();
Cause
It seems there are two causes:
-
pidusage.clear()
needs to be called, aspidusage
itself attaches a setInterval on the process. - There is race condition where
plugin.close()
can be called beforepidusage()
's first invocation can return. In that scenario,plugin._timeout
is null as it has never been initialized, and therefore the re-looping setTimeout never gets unregistered.
Hi, @DonutEspresso I'm curious about the issue you posted here. However, I'm new to restify. I wonder where pidusage()
is invoked as you mentioned. Thx.