Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timers: do not retain a reference to the async store after firing #53443

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Jun 13, 2024

After firing timers, we can clean them up by iterating over all active stores and setting the relevant symbols to undefined.

This is still a draft because we will need to extend it to immediates and intervals, too.

Fixes #53408

@nodejs-github-bot nodejs-github-bot added async_hooks Issues and PRs related to the async hooks subsystem. needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout. labels Jun 13, 2024
@mcollina
Copy link
Member Author

I've opened a draft PR to discuss a possible solution to #53408.

cc @nodejs/diagnostics @nodejs/timers let me know what you think.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@@ -429,6 +432,20 @@ function setPosition(node, pos) {
node.priorityQueuePosition = pos;
}

function removeAllStores (timer) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about moving this function into async_hooks to avoid the need to expose getActiveStores() there?
An alternative would be to use a single object on the resource which holds all stores. This would reduce the number of properties added on resource objects - and avoid the need of a for loop to clear it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A helper that receives a resource and clears all the store data off it would be better than exposing the stores list as we do now. As it is presently, one could get and retain access to a store in a way unintentional from the perspective of the store owner, which is a bit dangerous from a memory perspective.

@@ -594,6 +611,9 @@ function getTimerCallbacks(runNextTicks) {
if (timer[kRefed])
timeoutInfo[0]--;

removeAllStores(timer);
timer._onTimeout = undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe clear also _timerArgs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. needs-ci PRs that need a full CI run. timers Issues and PRs related to the timers subsystem / setImmediate, setInterval, setTimeout.
4 participants