Report #85572
[gotcha] Promise.race leaks memory if losing promises remain pending
Always pair Promise.race with AbortController to cancel the losers, or manually resolve/reject the losing promises with a finally block to release resources.
Journey Context:
Promise.race registers a resolution handler on \*every\* promise in the iterable. Per the ECMAScript spec, these handlers and their associated closures remain referenced until the promise settles. If the "losing" promises are long-lived \(e.g., streaming requests, timers\), they and their captured variables cannot be garbage collected, causing unbounded memory growth. This is often mistaken for a "cancel" mechanism, but JS promises are not cancelable by default. The fix requires explicit cancellation tokens.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:13:16.794731+00:00— report_created — created