lib: defer AbortSignal.any() following#62367
Open
Han5991 wants to merge 5 commits intonodejs:mainfrom
Open
Conversation
Avoid registering AbortSignal.any() composites as dependants until they are actually observed. This fixes the long-lived source retention pattern from nodejs#62363 while preserving abort semantics through lazy refresh and follow paths. Also unregister fired timeout signals from the timeout finalization registry so timeout churn releases memory more promptly.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62367 +/- ##
==========================================
- Coverage 91.60% 89.68% -1.92%
==========================================
Files 337 676 +339
Lines 140745 206752 +66007
Branches 21802 39593 +17791
==========================================
+ Hits 128925 185433 +56508
- Misses 11595 13465 +1870
- Partials 225 7854 +7629
🚀 New features to boost your workflow:
|
geeksilva97
approved these changes
Mar 22, 2026
Contributor
|
cc @atlowChemi |
atlowChemi
reviewed
Mar 22, 2026
The test depends on GC and heap behavior under a very small memory limit, which makes it too sensitive for CI. Remove the test and keep the cleanup change.
atlowChemi
approved these changes
Mar 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AbortSignal.any()until the composite is observedclearTimeoutRegistryto reduce timeout churn retentionProblem
AbortSignal.any()eagerly registered listener-less composites as dependants of their source signals. With a long-lived source, repeatedAbortSignal.any([source])calls accumulated inkDependantSignalsand retained memory (#62363).While investigating broader
AbortSignalchurn, timeout-only churn also kept timeout finalization registry entries alive after timers had fired, which delayed cleanup.What Changed
AbortSignal.any()aborted,reason, orthrowIfAborted()AbortSignal.timeout()clearTimeoutRegistryResults
#62363reproout/Release/nodestayed flat through 2,000,000 iterationskDependantSignalsstayed at0Timeout churn
AbortSignal.timeout(1)after GCrss 164.55 MiB,heap 23.15 MiBrss 67.19 MiB,heap 3.96 MiBAbortSignal.any([AbortSignal.timeout(1)])after GCrss 135.30 MiB,heap 7.85 MiBrss 74.22 MiB,heap 4.01 MiBTimeout churn logs
Before patch
With patch
Notes
The same-tick fresh
AbortControllermicrobenchmark from #54614 still shows heap growth until the next turn. That appears to be due toWeakRefcleanup semantics rather than long-lived source retention: the heap drops back after asetImmediate()and the weak references clear on the next turn.Testing
python3 tools/test.py test/parallel/test-abortsignal-any.mjs test/parallel/test-abort-controller-any-timeout.js test/parallel/test-abortsignal-drop-settled-signals.mjs test/parallel/test-abortsignal-timeout-memory.js test/parallel/test-abortcontroller.jsFixes: #62363
Refs: #54614