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

Leaky execution related to a race condition when a listener is added to a MemoryStream #53

Closed
wclr opened this issue Jun 15, 2016 · 3 comments

Comments

@wclr
Copy link
Contributor

wclr commented Jun 15, 2016

http://www.webpackbin.com/Ny3m5bc4-

See console output.

There is three ending listeners attached, one of the them (in the middle) takes 0 (or 1 item), and this causes kind of a leak after all all listeners detached
.

@wclr wclr mentioned this issue Jun 15, 2016
@staltz staltz changed the title Leaky case of of new imitate Leaky case of new imitate Jun 16, 2016
@wclr
Copy link
Contributor Author

wclr commented Jun 16, 2016

Not pointing on urgency but commenting the weight (could) - this issue needs to be checked and fixed because it may mean that there is something wrong with whole approach to inner cycles detection.

@Hypnosphi
Copy link
Contributor

Hypnosphi commented Jun 18, 2016

In fact, this bug has nothing to do with imitate and can be simplified to this: http://www.webpackbin.com/Vywzoz0E-

the problem here is the combination of MemoryStream with synchronous starting value and take(1).

Let's take a look at MemoryStream#_add method

_add(il: InternalListener<T>): void {
    if (this._has) { il._n(this._v); }
    super._add(il);
}

Here, if a value is already present (which is the case if there are already any listeners attached), it is emitted before the listener is really added. In case of take(1) it leads to instant completion of outer stream. TakeOperator therefore stops and tries to remove itself from the source$ MemoryStream internal listeners list. But it isn't present at that list yet, so it's a no-op. Then, in the second line of MemoryStream#_add, it finally adds itself and stays there forever.

A simple solution would be if MemoryStream just added listeners before emitting the current value, but I'm not sure it wouldn't lead to other bugs, so maybe a better option would be if operators removed itself asynchronously.

@staltz staltz changed the title Leaky case of new imitate Leaky execution related to a race condition when a listener is added to a MemoryStream Oct 24, 2016
@staltz staltz closed this as completed in 47e67ff Oct 24, 2016
@staltz
Copy link
Owner

staltz commented Oct 24, 2016

Fixed in v7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants