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

Delay operator will leak memory #3604

Closed
ubnt-michals opened this issue Apr 26, 2018 · 4 comments
Closed

Delay operator will leak memory #3604

ubnt-michals opened this issue Apr 26, 2018 · 4 comments

Comments

@ubnt-michals
Copy link
Contributor

RxJS version: 5 and 6

Code to reproduce:
5

const { Observable } = require('rxjs');

const setup = delay => Observable.timer(1)
  .repeatWhen(notifications => notifications.delay(delay))
  .subscribe();

let instances = 100;
while (instances--) {
  setup(100);
}

6

const { timer } = require('rxjs');
const { repeatWhen, delay } = require('rxjs/operators');

const setup = d => timer(1)
  .pipe(
    repeatWhen(notifications => notifications.pipe(delay(d)))
  )
  .subscribe();

let instances = 100;
while (instances--) {
  setup(100);
}

Expected behavior:
Memory shouldn't grow

Actual behavior:
Memory grows indefinitely

Additional information:
Have fix and will provide PR

@benlesh
Copy link
Member

benlesh commented Apr 26, 2018

I'm not sure this is a problem with delay so much as it might be a problem with repeatWhen. The recursive nature of what you're doing here is suspect.

@ubnt-michals
Copy link
Contributor Author

Where is the recursion? I running asynchronous action and resubscribing it with delay.

In synchronous code it would be something like

while(true) {
  doStuff()
  sleep(1)
}

The code above when replaced with

timer(1)
  .pipe(
    repeatWhen(notifications => notifications.pipe(mergeMapTo(timer(d))))
  )
  .subscribe();

is not leaking.

@ubnt-michals
Copy link
Contributor Author

Fixed in #3605

@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants