restify / restify/node-restify
cpuUsageThrottle plugin `close()` does not clean up properly
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 975
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 5
Description
- Used appropriate template for the issue type
- Searched both open and closed issues for duplicates of this issue
- 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, aspidusageitself 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._timeoutis null as it has never been initialized, and therefore the re-looping setTimeout never gets unregistered.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the cpuUsageThrottle plugin and its close() path; inspect the pidusage cleanup and the plugin._timeout race described in the report. Reproduce the supplied snippet, then verify that close() releases all handles and allows the process to exit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100