timers: do not retain a reference to the async store after firing#53443
timers: do not retain a reference to the async store after firing#53443mcollina wants to merge 1 commit into
Conversation
|
I've opened a draft PR to discuss a possible solution to #53408. cc @nodejs/diagnostics @nodejs/timers let me know what you think. |
| node.priorityQueuePosition = pos; | ||
| } | ||
|
|
||
| function removeAllStores (timer) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| timeoutInfo[0]--; | ||
|
|
||
| removeAllStores(timer); | ||
| timer._onTimeout = undefined; |
After firing timers, we can clean them up by iterating over all active stores and setting the relevant symbols to undefined. This also covers immediates and intervals. Refs: nodejs#53408 PR-URL: nodejs#53443 Fixes: nodejs#53408
|
I've updated this PR to address the review feedback:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #53443 +/- ##
=======================================
Coverage 90.34% 90.34%
=======================================
Files 732 732
Lines 236455 236542 +87
Branches 44528 44534 +6
=======================================
+ Hits 213615 213697 +82
- Misses 14544 14545 +1
- Partials 8296 8300 +4
🚀 New features to boost your workflow:
|
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