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
Scheduler memory leak on v7 #6624
Comments
Woosh, I spent 3 days on your issues tracker, searching for any reference to any issue similar to mines, I can't believe I didn't see those PRs 🤦 |
Yes sorry, I forgot to file an issue but directly headed over to PR. my bad. |
@andrevmatos I've just published these fixes as 7.3.1. Give that a try. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
Current Behavior
While investigating redux-observable/redux-observable#754 , it seems the root cause is actually on
rxjs@7
's scheduler code. It seems that whenever we use an inner observable (mergeMap
ed) where the outer observable isscheduled
orobserveOn(queueScheduler)
, it leaks thousands ofQueueAction
s retained byOperatorSubscriber._teardowns
, holding potentially heavy contexts in memory, and aren't freed even after that observable chain is completed and no reference to these variables are kept in the application. On our real world redux-observable app, every emitted action holds with it its context, including redux's state, quickly filling up all available memory.It seems this also affects
asyncScheduler
.This bug seems to NOT happen on
rxjs@6
with same code.This bug looks like #6458 , but differently from that, we create just a few thousand values in memory, and give the opportunity for the queue to flush, and even though it processes normally, the *Actions leak and are never freed. It also happens with lazy and async generators, instead of
range
. The problem is not the peak memory usage while processing the inner observable, but instead the garbage which accumulates and is never collected after the inner observable completes.Expected behavior
The scheduled
QueueAction
objects and their contexts should be freed after the observable completes. Memory usage after the__end
is expected to be below 10MB, but e.g. on Node14 it ends above 40MB.Reproduction
** I got some trouble taking a
Heap snapshot
on Chrome on the repro code. A workaround is to paste this code in anindex.mjs
file in a NodeJS 14.x project containing onlyrxjs@^7.3.0
as dependency, runningnode --inspect-brk index.mjs
and connectingchrome://inspect
to it. After code ends, lastsetTimeout
will keep process open, and aHeap snapshot
will show 50k+QueueAction
s laying in memory and never getting cleared. **Environment
Possible Solution
Additional context/Screenshots
The text was updated successfully, but these errors were encountered: